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

Side by Side Diff: chrome/browser/extensions/api/push_messaging/push_messaging_api.cc

Issue 11496004: Lazy initialization for PushMessagingEventRouter (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years 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/push_messaging/push_messaging_api.h" 5 #include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/extensions/api/push_messaging/push_messaging_api_factor y.h"
13 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati on_handler.h" 14 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati on_handler.h"
14 #include "chrome/browser/extensions/event_names.h" 15 #include "chrome/browser/extensions/event_names.h"
15 #include "chrome/browser/extensions/event_router.h" 16 #include "chrome/browser/extensions/event_router.h"
16 #include "chrome/browser/extensions/extension_service.h" 17 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/extension_system.h" 18 #include "chrome/browser/extensions/extension_system.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/signin/token_service.h" 20 #include "chrome/browser/signin/token_service.h"
20 #include "chrome/browser/signin/token_service_factory.h" 21 #include "chrome/browser/signin/token_service_factory.h"
21 #include "chrome/browser/sync/profile_sync_service.h" 22 #include "chrome/browser/sync/profile_sync_service.h"
22 #include "chrome/browser/sync/profile_sync_service_factory.h" 23 #include "chrome/browser/sync/profile_sync_service_factory.h"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 std::string error_text = error.error_message(); 284 std::string error_text = error.error_message();
284 // If the error message is blank, see if we can set it from the state. 285 // If the error message is blank, see if we can set it from the state.
285 if (error_text.empty() && 286 if (error_text.empty() &&
286 (0 != error.state())) { 287 (0 != error.state())) {
287 error_text = base::IntToString(error.state()); 288 error_text = base::IntToString(error.state());
288 } 289 }
289 290
290 ReportResult(std::string(), error_text); 291 ReportResult(std::string(), error_text);
291 } 292 }
292 293
294 PushMessagingAPI::PushMessagingAPI(Profile* profile)
295 : profile_(profile) {
296 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
297 this, event_names::kOnPushMessage);
298 }
299
300 PushMessagingAPI::~PushMessagingAPI() {
301 }
302
303 // static
304 PushMessagingAPI* PushMessagingAPI::Get(Profile* profile) {
305 return PushMessagingAPIFactory::GetForProfile(profile);
306 }
307
308 PushMessagingEventRouter* PushMessagingAPI::push_messaging_event_router() {
309 if (!push_messaging_event_router_)
310 push_messaging_event_router_.reset(new PushMessagingEventRouter(profile_));
311 return push_messaging_event_router_.get();
312 }
313
314 void PushMessagingAPI::OnProfileSyncServiceShutdown() {
315 // TODO(akalin): Move this block to Shutdown() once
Yoyo Zhou 2012/12/10 20:06:01 I believe you can do this and get rid of OnProfile
akalin 2012/12/10 20:37:12 Yeah, per your other comment, I agree.
Joe Thomas 2012/12/10 22:43:58 Done.
316 // http://crbug.com/153827 is fixed.
317 if (push_messaging_event_router_.get())
318 push_messaging_event_router_->Shutdown();
319 }
320
321 void PushMessagingAPI::Shutdown() {
322 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
323 }
324
325 void PushMessagingAPI::OnListenerAdded(
326 const extensions::EventListenerInfo& details) {
327 push_messaging_event_router();
328 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
329 }
330
293 } // namespace extensions 331 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698