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

Side by Side Diff: chrome/browser/extensions/api/idle/idle_manager.cc

Issue 238633009: cleanup: Use EventRouter instead of ExtensionSystem::Get->event_router() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile error for chromeos build. Created 6 years, 8 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 (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/idle/idle_manager.h" 5 #include "chrome/browser/extensions/api/idle/idle_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/extensions/api/idle/idle_api_constants.h" 11 #include "chrome/browser/extensions/api/idle/idle_api_constants.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/extensions/api/idle.h" 13 #include "chrome/common/extensions/api/idle.h"
14 #include "chrome/common/extensions/extension_constants.h" 14 #include "chrome/common/extensions/extension_constants.h"
15 #include "content/public/browser/notification_details.h" 15 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_source.h" 16 #include "content/public/browser/notification_source.h"
17 #include "extensions/browser/event_router.h" 17 #include "extensions/browser/event_router.h"
18 #include "extensions/browser/extension_system.h"
19 #include "extensions/common/extension.h" 18 #include "extensions/common/extension.h"
20 19
21 namespace keys = extensions::idle_api_constants; 20 namespace keys = extensions::idle_api_constants;
22 namespace idle = extensions::api::idle; 21 namespace idle = extensions::api::idle;
23 22
24 namespace extensions { 23 namespace extensions {
25 24
26 namespace { 25 namespace {
27 26
28 const int kDefaultIdleThreshold = 60; 27 const int kDefaultIdleThreshold = 60;
(...skipping 20 matching lines...) Expand all
49 DefaultEventDelegate::~DefaultEventDelegate() { 48 DefaultEventDelegate::~DefaultEventDelegate() {
50 } 49 }
51 50
52 void DefaultEventDelegate::OnStateChanged(const std::string& extension_id, 51 void DefaultEventDelegate::OnStateChanged(const std::string& extension_id,
53 IdleState new_state) { 52 IdleState new_state) {
54 scoped_ptr<base::ListValue> args(new base::ListValue()); 53 scoped_ptr<base::ListValue> args(new base::ListValue());
55 args->Append(IdleManager::CreateIdleValue(new_state)); 54 args->Append(IdleManager::CreateIdleValue(new_state));
56 scoped_ptr<Event> event(new Event(idle::OnStateChanged::kEventName, 55 scoped_ptr<Event> event(new Event(idle::OnStateChanged::kEventName,
57 args.Pass())); 56 args.Pass()));
58 event->restrict_to_browser_context = profile_; 57 event->restrict_to_browser_context = profile_;
59 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( 58 EventRouter::Get(profile_)
60 extension_id, event.Pass()); 59 ->DispatchEventToExtension(extension_id, event.Pass());
61 } 60 }
62 61
63 void DefaultEventDelegate::RegisterObserver( 62 void DefaultEventDelegate::RegisterObserver(
64 EventRouter::Observer* observer) { 63 EventRouter::Observer* observer) {
65 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( 64 EventRouter::Get(profile_)
66 observer, idle::OnStateChanged::kEventName); 65 ->RegisterObserver(observer, idle::OnStateChanged::kEventName);
67 } 66 }
68 67
69 void DefaultEventDelegate::UnregisterObserver(EventRouter::Observer* observer) { 68 void DefaultEventDelegate::UnregisterObserver(EventRouter::Observer* observer) {
70 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(observer); 69 EventRouter::Get(profile_)->UnregisterObserver(observer);
71 } 70 }
72 71
73
74 class DefaultIdleProvider : public IdleManager::IdleTimeProvider { 72 class DefaultIdleProvider : public IdleManager::IdleTimeProvider {
75 public: 73 public:
76 DefaultIdleProvider(); 74 DefaultIdleProvider();
77 virtual ~DefaultIdleProvider(); 75 virtual ~DefaultIdleProvider();
78 76
79 virtual void CalculateIdleState(int idle_threshold, 77 virtual void CalculateIdleState(int idle_threshold,
80 IdleCallback notify) OVERRIDE; 78 IdleCallback notify) OVERRIDE;
81 virtual void CalculateIdleTime(IdleTimeCallback notify) OVERRIDE; 79 virtual void CalculateIdleTime(IdleTimeCallback notify) OVERRIDE;
82 virtual bool CheckIdleStateIsLocked() OVERRIDE; 80 virtual bool CheckIdleStateIsLocked() OVERRIDE;
83 }; 81 };
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 event_delegate_->OnStateChanged(it->first, new_state); 273 event_delegate_->OnStateChanged(it->first, new_state);
276 } 274 }
277 } 275 }
278 276
279 if (listener_count == 0) { 277 if (listener_count == 0) {
280 StopPolling(); 278 StopPolling();
281 } 279 }
282 } 280 }
283 281
284 } // namespace extensions 282 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698