Chromium Code Reviews| OLD | NEW |
|---|---|
| 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> | |
|
bartfab (slow)
2013/06/21 18:18:13
What is this used for?
xiyuan
2013/06/21 18:33:18
For std::pair used in old code in this file.
| |
| 8 | |
| 9 #include "base/logging.h" | |
| 7 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/values.h" | |
| 8 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/extensions/event_router.h" | 13 #include "chrome/browser/extensions/event_router.h" |
| 10 #include "chrome/browser/extensions/extension_host.h" | 14 #include "chrome/browser/extensions/extension_host.h" |
| 11 #include "chrome/browser/extensions/extension_process_manager.h" | 15 #include "chrome/browser/extensions/extension_process_manager.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_system.h" | 17 #include "chrome/browser/extensions/extension_system.h" |
| 14 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 18 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
| 15 #include "chrome/browser/extensions/updater/extension_updater.h" | 19 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 29 | 33 |
| 30 namespace extensions { | 34 namespace extensions { |
| 31 | 35 |
| 32 namespace { | 36 namespace { |
| 33 | 37 |
| 34 const char kOnStartupEvent[] = "runtime.onStartup"; | 38 const char kOnStartupEvent[] = "runtime.onStartup"; |
| 35 const char kOnInstalledEvent[] = "runtime.onInstalled"; | 39 const char kOnInstalledEvent[] = "runtime.onInstalled"; |
| 36 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; | 40 const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; |
| 37 const char kOnBrowserUpdateAvailableEvent[] = | 41 const char kOnBrowserUpdateAvailableEvent[] = |
| 38 "runtime.onBrowserUpdateAvailable"; | 42 "runtime.onBrowserUpdateAvailable"; |
| 43 const char kOnRestartRequiredEvent[] = "runtime.onRestartRequired"; | |
| 39 const char kNoBackgroundPageError[] = "You do not have a background page."; | 44 const char kNoBackgroundPageError[] = "You do not have a background page."; |
| 40 const char kPageLoadError[] = "Background page failed to load."; | 45 const char kPageLoadError[] = "Background page failed to load."; |
| 41 const char kInstallReason[] = "reason"; | 46 const char kInstallReason[] = "reason"; |
| 42 const char kInstallReasonChromeUpdate[] = "chrome_update"; | 47 const char kInstallReasonChromeUpdate[] = "chrome_update"; |
| 43 const char kInstallReasonUpdate[] = "update"; | 48 const char kInstallReasonUpdate[] = "update"; |
| 44 const char kInstallReasonInstall[] = "install"; | 49 const char kInstallReasonInstall[] = "install"; |
| 45 const char kInstallPreviousVersion[] = "previousVersion"; | 50 const char kInstallPreviousVersion[] = "previousVersion"; |
| 46 const char kInvalidUrlError[] = "Invalid URL."; | 51 const char kInvalidUrlError[] = "Invalid URL."; |
| 52 const char kRestartReasonAppUpdate[] = "app_update"; | |
| 53 const char kRestartReasonOsUpdate[] = "os_update"; | |
| 54 const char kRestartReasonPeriodic[] = "periodic"; | |
| 47 const char kUpdatesDisabledError[] = "Autoupdate is not enabled."; | 55 const char kUpdatesDisabledError[] = "Autoupdate is not enabled."; |
| 48 const char kUpdateFound[] = "update_available"; | 56 const char kUpdateFound[] = "update_available"; |
| 49 const char kUpdateNotFound[] = "no_update"; | 57 const char kUpdateNotFound[] = "no_update"; |
| 50 const char kUpdateThrottled[] = "throttled"; | 58 const char kUpdateThrottled[] = "throttled"; |
| 51 | 59 |
| 52 // A preference key storing the url loaded when an extension is uninstalled. | 60 // A preference key storing the url loaded when an extension is uninstalled. |
| 53 const char kUninstallUrl[] = "uninstall_url"; | 61 const char kUninstallUrl[] = "uninstall_url"; |
| 54 | 62 |
| 55 static void DispatchOnStartupEventImpl( | 63 static void DispatchOnStartupEventImpl( |
| 56 Profile* profile, | 64 Profile* profile, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 return; | 183 return; |
| 176 | 184 |
| 177 scoped_ptr<ListValue> args(new ListValue); | 185 scoped_ptr<ListValue> args(new ListValue); |
| 178 DCHECK(system->event_router()); | 186 DCHECK(system->event_router()); |
| 179 scoped_ptr<Event> event(new Event(kOnBrowserUpdateAvailableEvent, | 187 scoped_ptr<Event> event(new Event(kOnBrowserUpdateAvailableEvent, |
| 180 args.Pass())); | 188 args.Pass())); |
| 181 system->event_router()->BroadcastEvent(event.Pass()); | 189 system->event_router()->BroadcastEvent(event.Pass()); |
| 182 } | 190 } |
| 183 | 191 |
| 184 // static | 192 // static |
| 193 void RuntimeEventRouter::DispatchOnRestartRequiredEvent( | |
| 194 Profile* profile, | |
| 195 const std::string& app_id, | |
| 196 RestartReason reason) { | |
| 197 ExtensionSystem* system = ExtensionSystem::Get(profile); | |
| 198 if (!system) | |
| 199 return; | |
| 200 | |
| 201 scoped_ptr<ListValue> args(new ListValue); | |
| 202 switch (reason) { | |
| 203 case RESTART_REASON_APP_UPDATE: | |
| 204 args->AppendString(kRestartReasonAppUpdate); | |
| 205 break; | |
| 206 case RESTART_REASON_OS_UPDATE: | |
| 207 args->AppendString(kRestartReasonOsUpdate); | |
| 208 break; | |
| 209 case RESTART_REASON_PERIODIC: | |
| 210 args->AppendString(kRestartReasonPeriodic); | |
| 211 break; | |
| 212 default: | |
| 213 NOTREACHED() << "Unknown reboot reason=" << reason; | |
|
bartfab (slow)
2013/06/21 18:18:13
Nit: s/reboot/restart/
xiyuan
2013/06/21 18:33:18
Done.
| |
| 214 return; | |
| 215 } | |
| 216 | |
| 217 DCHECK(system->event_router()); | |
| 218 scoped_ptr<Event> event(new Event(kOnRestartRequiredEvent, args.Pass())); | |
| 219 system->event_router()->DispatchEventToExtension(app_id, event.Pass()); | |
| 220 } | |
| 221 | |
| 222 // static | |
| 185 void RuntimeEventRouter::OnExtensionUninstalled( | 223 void RuntimeEventRouter::OnExtensionUninstalled( |
| 186 Profile *profile, | 224 Profile* profile, |
| 187 const std::string& extension_id) { | 225 const std::string& extension_id) { |
| 188 #if defined(ENABLE_EXTENSIONS) | 226 #if defined(ENABLE_EXTENSIONS) |
| 189 GURL uninstall_url(GetUninstallUrl(ExtensionPrefs::Get(profile), | 227 GURL uninstall_url(GetUninstallUrl(ExtensionPrefs::Get(profile), |
| 190 extension_id)); | 228 extension_id)); |
| 191 | 229 |
| 192 if (uninstall_url.is_empty()) | 230 if (uninstall_url.is_empty()) |
| 193 return; | 231 return; |
| 194 | 232 |
| 195 Browser* browser = chrome::FindLastActiveWithProfile(profile, | 233 Browser* browser = chrome::FindLastActiveWithProfile(profile, |
| 196 chrome::GetActiveDesktop()); | 234 chrome::GetActiveDesktop()); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 } else { | 412 } else { |
| 375 NOTREACHED(); | 413 NOTREACHED(); |
| 376 return false; | 414 return false; |
| 377 } | 415 } |
| 378 | 416 |
| 379 results_ = GetPlatformInfo::Results::Create(info); | 417 results_ = GetPlatformInfo::Results::Create(info); |
| 380 return true; | 418 return true; |
| 381 } | 419 } |
| 382 | 420 |
| 383 } // namespace extensions | 421 } // namespace extensions |
| OLD | NEW |