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

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

Issue 1970613003: Add a new app API to enable watchdog behavior restarts in kiosk apps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missing include Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chrome_runtime_api_delegate.h" 5 #include "chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/extensions/extension_tab_util.h" 21 #include "chrome/browser/extensions/extension_tab_util.h"
21 #include "chrome/browser/extensions/updater/extension_updater.h" 22 #include "chrome/browser/extensions/updater/extension_updater.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/browser_finder.h" 24 #include "chrome/browser/ui/browser_finder.h"
24 #include "chrome/browser/ui/browser_navigator.h" 25 #include "chrome/browser/ui/browser_navigator.h"
25 #include "chrome/browser/ui/browser_navigator_params.h" 26 #include "chrome/browser/ui/browser_navigator_params.h"
26 #include "chrome/browser/ui/browser_window.h" 27 #include "chrome/browser/ui/browser_window.h"
27 #include "components/update_client/update_query_params.h" 28 #include "components/update_client/update_query_params.h"
28 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 }; 133 };
133 134
134 ChromeRuntimeAPIDelegate::ChromeRuntimeAPIDelegate( 135 ChromeRuntimeAPIDelegate::ChromeRuntimeAPIDelegate(
135 content::BrowserContext* context) 136 content::BrowserContext* context)
136 : browser_context_(context), 137 : browser_context_(context),
137 registered_for_updates_(false), 138 registered_for_updates_(false),
138 extension_registry_observer_(this) { 139 extension_registry_observer_(this) {
139 registrar_.Add(this, 140 registrar_.Add(this,
140 extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND, 141 extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND,
141 content::NotificationService::AllSources()); 142 content::NotificationService::AllSources());
143 registrar_.Add(this,
144 chrome::NOTIFICATION_APP_TERMINATING,
145 content::NotificationService::AllSources());
142 extension_registry_observer_.Add( 146 extension_registry_observer_.Add(
143 extensions::ExtensionRegistry::Get(browser_context_)); 147 extensions::ExtensionRegistry::Get(browser_context_));
144 } 148 }
145 149
146 ChromeRuntimeAPIDelegate::~ChromeRuntimeAPIDelegate() { 150 ChromeRuntimeAPIDelegate::~ChromeRuntimeAPIDelegate() {
147 } 151 }
148 152
149 // static 153 // static
150 void ChromeRuntimeAPIDelegate::set_tick_clock_for_tests( 154 void ChromeRuntimeAPIDelegate::set_tick_clock_for_tests(
151 base::TickClock* clock) { 155 base::TickClock* clock) {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 chromeos::DBusThreadManager::Get() 321 chromeos::DBusThreadManager::Get()
318 ->GetPowerManagerClient() 322 ->GetPowerManagerClient()
319 ->RequestRestart(); 323 ->RequestRestart();
320 return true; 324 return true;
321 } 325 }
322 #endif 326 #endif
323 *error_message = "Function available only for ChromeOS kiosk mode."; 327 *error_message = "Function available only for ChromeOS kiosk mode.";
324 return false; 328 return false;
325 } 329 }
326 330
331 void ChromeRuntimeAPIDelegate::SetOnDeviceShutdownCallback(
332 const base::Closure& callback) {
333 on_device_shutdown_callback_ = callback;
334 }
335
327 bool ChromeRuntimeAPIDelegate::OpenOptionsPage(const Extension* extension) { 336 bool ChromeRuntimeAPIDelegate::OpenOptionsPage(const Extension* extension) {
328 Profile* profile = Profile::FromBrowserContext(browser_context_); 337 Profile* profile = Profile::FromBrowserContext(browser_context_);
329 Browser* browser = chrome::FindLastActiveWithProfile(profile); 338 Browser* browser = chrome::FindLastActiveWithProfile(profile);
330 if (!browser) 339 if (!browser)
331 return false; 340 return false;
332 return extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser); 341 return extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser);
333 } 342 }
334 343
335 void ChromeRuntimeAPIDelegate::Observe( 344 void ChromeRuntimeAPIDelegate::Observe(
336 int type, 345 int type,
337 const content::NotificationSource& source, 346 const content::NotificationSource& source,
338 const content::NotificationDetails& details) { 347 const content::NotificationDetails& details) {
339 DCHECK(type == extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND); 348 switch (type) {
340 typedef const std::pair<std::string, Version> UpdateDetails; 349 case chrome::NOTIFICATION_APP_TERMINATING:
341 const std::string& id = content::Details<UpdateDetails>(details)->first; 350 if (!on_device_shutdown_callback_.is_null())
342 const Version& version = content::Details<UpdateDetails>(details)->second; 351 on_device_shutdown_callback_.Run();
343 if (version.IsValid()) { 352 break;
344 CallUpdateCallbacks( 353
345 id, UpdateCheckResult(true, kUpdateFound, version.GetString())); 354 case extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND: {
355 typedef const std::pair<std::string, Version> UpdateDetails;
356 const std::string& id = content::Details<UpdateDetails>(details)->first;
357 const Version& version = content::Details<UpdateDetails>(details)->second;
358 if (version.IsValid()) {
359 CallUpdateCallbacks(
360 id, UpdateCheckResult(true, kUpdateFound, version.GetString()));
361 }
362 break;
363 }
364
365 default:
366 NOTREACHED() << "Unexpected notification.";
346 } 367 }
347 } 368 }
348 369
349 void ChromeRuntimeAPIDelegate::OnExtensionInstalled( 370 void ChromeRuntimeAPIDelegate::OnExtensionInstalled(
350 content::BrowserContext* browser_context, 371 content::BrowserContext* browser_context,
351 const Extension* extension, 372 const Extension* extension,
352 bool is_update) { 373 bool is_update) {
353 if (!is_update) 374 if (!is_update)
354 return; 375 return;
355 auto info = update_check_info_.find(extension->id()); 376 auto info = update_check_info_.find(extension->id());
(...skipping 30 matching lines...) Expand all
386 const UpdateCheckResult& result) { 407 const UpdateCheckResult& result) {
387 auto it = update_check_info_.find(extension_id); 408 auto it = update_check_info_.find(extension_id);
388 if (it == update_check_info_.end()) 409 if (it == update_check_info_.end())
389 return; 410 return;
390 std::vector<UpdateCheckCallback> callbacks; 411 std::vector<UpdateCheckCallback> callbacks;
391 it->second.callbacks.swap(callbacks); 412 it->second.callbacks.swap(callbacks);
392 for (const auto& callback : callbacks) { 413 for (const auto& callback : callbacks) {
393 callback.Run(result); 414 callback.Run(result);
394 } 415 }
395 } 416 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698