Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: chrome/browser/extensions/api/runtime/runtime_api.cc

Issue 16844020: app_mode: Add runtime.onRestartRequired event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/runtime/runtime_api.h" 5 #include "chrome/browser/extensions/api/runtime/runtime_api.h"
6 6
7 #include <utility>
8
7 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/event_router.h" 11 #include "chrome/browser/extensions/event_router.h"
10 #include "chrome/browser/extensions/extension_host.h" 12 #include "chrome/browser/extensions/extension_host.h"
11 #include "chrome/browser/extensions/extension_process_manager.h" 13 #include "chrome/browser/extensions/extension_process_manager.h"
12 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_system.h" 15 #include "chrome/browser/extensions/extension_system.h"
14 #include "chrome/browser/extensions/lazy_background_task_queue.h" 16 #include "chrome/browser/extensions/lazy_background_task_queue.h"
15 #include "chrome/browser/extensions/updater/extension_updater.h" 17 #include "chrome/browser/extensions/updater/extension_updater.h"
16 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
(...skipping 12 matching lines...) Expand all
29 31
30 namespace extensions { 32 namespace extensions {
31 33
32 namespace { 34 namespace {
33 35
34 const char kOnStartupEvent[] = "runtime.onStartup"; 36 const char kOnStartupEvent[] = "runtime.onStartup";
35 const char kOnInstalledEvent[] = "runtime.onInstalled"; 37 const char kOnInstalledEvent[] = "runtime.onInstalled";
36 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; 38 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable";
37 const char kOnBrowserUpdateAvailableEvent[] = 39 const char kOnBrowserUpdateAvailableEvent[] =
38 "runtime.onBrowserUpdateAvailable"; 40 "runtime.onBrowserUpdateAvailable";
41 const char kOnRestartRequiredEvent[] = "runtime.onRestartRequired";
39 const char kNoBackgroundPageError[] = "You do not have a background page."; 42 const char kNoBackgroundPageError[] = "You do not have a background page.";
40 const char kPageLoadError[] = "Background page failed to load."; 43 const char kPageLoadError[] = "Background page failed to load.";
41 const char kInstallReason[] = "reason"; 44 const char kInstallReason[] = "reason";
42 const char kInstallReasonChromeUpdate[] = "chrome_update"; 45 const char kInstallReasonChromeUpdate[] = "chrome_update";
43 const char kInstallReasonUpdate[] = "update"; 46 const char kInstallReasonUpdate[] = "update";
44 const char kInstallReasonInstall[] = "install"; 47 const char kInstallReasonInstall[] = "install";
45 const char kInstallPreviousVersion[] = "previousVersion"; 48 const char kInstallPreviousVersion[] = "previousVersion";
46 const char kInvalidUrlError[] = "Invalid URL."; 49 const char kInvalidUrlError[] = "Invalid URL.";
50 const char kRestartReason[] = "reason";
51 const char kRestartReasonAppUpdate[] = "app_update";
52 const char kRestartReasonOsUpdate[] = "os_update";
53 const char kRestartReasonPeriodic[] = "periodic";
47 const char kUpdatesDisabledError[] = "Autoupdate is not enabled."; 54 const char kUpdatesDisabledError[] = "Autoupdate is not enabled.";
48 const char kUpdateFound[] = "update_available"; 55 const char kUpdateFound[] = "update_available";
49 const char kUpdateNotFound[] = "no_update"; 56 const char kUpdateNotFound[] = "no_update";
50 const char kUpdateThrottled[] = "throttled"; 57 const char kUpdateThrottled[] = "throttled";
51 58
52 // A preference key storing the url loaded when an extension is uninstalled. 59 // A preference key storing the url loaded when an extension is uninstalled.
53 const char kUninstallUrl[] = "uninstall_url"; 60 const char kUninstallUrl[] = "uninstall_url";
54 61
55 static void DispatchOnStartupEventImpl( 62 static void DispatchOnStartupEventImpl(
56 Profile* profile, 63 Profile* profile,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return; 182 return;
176 183
177 scoped_ptr<ListValue> args(new ListValue); 184 scoped_ptr<ListValue> args(new ListValue);
178 DCHECK(system->event_router()); 185 DCHECK(system->event_router());
179 scoped_ptr<Event> event(new Event(kOnBrowserUpdateAvailableEvent, 186 scoped_ptr<Event> event(new Event(kOnBrowserUpdateAvailableEvent,
180 args.Pass())); 187 args.Pass()));
181 system->event_router()->BroadcastEvent(event.Pass()); 188 system->event_router()->BroadcastEvent(event.Pass());
182 } 189 }
183 190
184 // static 191 // static
192 void RuntimeEventRouter::DispatchOnRestartRequiredEvent(
193 Profile* profile,
194 const std::string& app_id,
195 RestartReason reason) {
196 ExtensionSystem* system = ExtensionSystem::Get(profile);
197 if (!system)
198 return;
199
200 scoped_ptr<ListValue> args(new ListValue);
bartfab (slow) 2013/06/17 23:30:59 Nit: #include <base/values.h>
xiyuan 2013/06/20 02:17:12 Done.
201 switch (reason) {
202 case RESTART_REASON_APP_UPDATE:
203 args->AppendString(kRestartReasonAppUpdate);
204 break;
205 case RESTART_REASON_OS_UPDATE:
206 args->AppendString(kRestartReasonOsUpdate);
207 break;
208 case RESTART_REASON_PERIODIC:
209 args->AppendString(kRestartReasonPeriodic);
210 break;
211 }
bartfab (slow) 2013/06/17 23:30:59 Nit: Add a fallback with a DCHECK() for invalid |r
xiyuan 2013/06/20 02:17:12 Done.
212
213 DCHECK(system->event_router());
bartfab (slow) 2013/06/17 23:30:59 Nit: Include <base/logging.h>
xiyuan 2013/06/20 02:17:12 Done.
214 scoped_ptr<Event> event(new Event(kOnRestartRequiredEvent, args.Pass()));
215 system->event_router()->DispatchEventToExtension(app_id, event.Pass());
216 }
217
218 // static
185 void RuntimeEventRouter::OnExtensionUninstalled( 219 void RuntimeEventRouter::OnExtensionUninstalled(
186 Profile *profile, 220 Profile* profile,
187 const std::string& extension_id) { 221 const std::string& extension_id) {
188 #if defined(ENABLE_EXTENSIONS) 222 #if defined(ENABLE_EXTENSIONS)
189 GURL uninstall_url(GetUninstallUrl(ExtensionPrefs::Get(profile), 223 GURL uninstall_url(GetUninstallUrl(ExtensionPrefs::Get(profile),
190 extension_id)); 224 extension_id));
191 225
192 if (uninstall_url.is_empty()) 226 if (uninstall_url.is_empty())
193 return; 227 return;
194 228
195 Browser* browser = chrome::FindLastActiveWithProfile(profile, 229 Browser* browser = chrome::FindLastActiveWithProfile(profile,
196 chrome::GetActiveDesktop()); 230 chrome::GetActiveDesktop());
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 } else { 408 } else {
375 NOTREACHED(); 409 NOTREACHED();
376 return false; 410 return false;
377 } 411 }
378 412
379 results_ = GetPlatformInfo::Results::Create(info); 413 results_ = GetPlatformInfo::Results::Create(info);
380 return true; 414 return true;
381 } 415 }
382 416
383 } // namespace extensions 417 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698