auto_updater::AutoUpdater::SetDelegate(NULL);
}
+void AutoUpdater::OnError(const std::string& error) {
+ base::ListValue args;
+ args.AppendString(error);
+ Emit("error", &args);
+}
+
+void AutoUpdater::OnUpdateNotAvailable() {
+ Emit("update-not-available");
+}
+
void AutoUpdater::OnUpdateDownloaded(const std::string& release_notes,
const std::string& release_name,
const base::Time& release_date,
explicit AutoUpdater(v8::Handle<v8::Object> wrapper);
// AutoUpdaterDelegate implementations.
+ virtual void OnError(const std::string& error) OVERRIDE;
+ virtual void OnUpdateNotAvailable() OVERRIDE;
virtual void OnUpdateDownloaded(
const std::string& release_notes,
const std::string& release_name,
class AutoUpdaterDelegate {
public:
+ // An error happened.
+ virtual void OnError(const std::string& error) {}
+
+ // There is no available update.
+ virtual void OnUpdateNotAvailable() {}
+
// There is a new update which has been downloaded.
virtual void OnUpdateDownloaded(const std::string& release_notes,
const std::string& release_name,
NSURLRequest* urlRequest = [NSURLRequest requestWithURL:url];
g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest];
+ AutoUpdaterDelegate* delegate = GetDelegate();
+ if (!delegate)
+ return;
+
// Subscribe to events.
+ __block bool has_update = false;
[g_updater.updates subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) {
- AutoUpdaterDelegate* delegate = GetDelegate();
- if (!delegate)
- return;
-
- SQRLUpdate* update = downloadedUpdate.update;
- delegate->OnUpdateDownloaded(
- base::SysNSStringToUTF8(update.releaseNotes),
- base::SysNSStringToUTF8(update.releaseName),
- base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970),
- base::SysNSStringToUTF8(update.updateURL.absoluteString),
- base::Bind(RelaunchToInstallUpdate));
+ has_update = true;
+
+ // There is a new update that has been downloaded.
+ SQRLUpdate* update = downloadedUpdate.update;
+ delegate->OnUpdateDownloaded(
+ base::SysNSStringToUTF8(update.releaseNotes),
+ base::SysNSStringToUTF8(update.releaseName),
+ base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970),
+ base::SysNSStringToUTF8(update.updateURL.absoluteString),
+ base::Bind(RelaunchToInstallUpdate));
+ } error:^(NSError* error) {
+ // Something wrong happened.
+ delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription));
+ } completed:^() {
+ // When the completed event is sent with no update, then we know there
+ // is no update available.
+ if (!has_update)
+ delegate->OnUpdateNotAvailable();
+ has_update = false;
}];
}
}