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

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

Issue 10836182: Obfuscated Gaia ID fetcher (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: CR changes per Munjal Created 8 years, 4 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/push_messaging/push_messaging_api.h" 5 #include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/event_names.h" 9 #include "chrome/browser/extensions/event_names.h"
10 #include "chrome/browser/extensions/event_router.h" 10 #include "chrome/browser/extensions/event_router.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/signin/token_service.h"
14 #include "chrome/browser/signin/token_service_factory.h"
12 #include "chrome/common/extensions/api/experimental_push_messaging.h" 15 #include "chrome/common/extensions/api/experimental_push_messaging.h"
16 #include "chrome/common/net/gaia/google_service_auth_error.h"
13 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
14 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
19 #include "obfuscated_gaia_id_fetcher.h"
15 20
16 namespace extensions { 21 namespace extensions {
17 22
18 namespace glue = extensions::api::experimental_push_messaging; 23 namespace glue = extensions::api::experimental_push_messaging;
19 24
20 PushMessagingEventRouter::PushMessagingEventRouter(Profile* profile) 25 PushMessagingEventRouter::PushMessagingEventRouter(Profile* profile)
21 : profile_(profile) { 26 : profile_(profile) {
22 } 27 }
23 28
24 PushMessagingEventRouter::~PushMessagingEventRouter() {} 29 PushMessagingEventRouter::~PushMessagingEventRouter() {}
25 30
31 // TODO: Move these methods to be on the class that eventually creates
32 // the Obfuscated Gaia ID fetcher, and pass "this" from that class for
33 // the delegate.
34 class GaiaFetcherDelegate : public ObfuscatedGaiaIdFetcher::Delegate {
35 public:
36 GaiaFetcherDelegate() {}
37 virtual ~GaiaFetcherDelegate() {}
38 virtual void OnObfuscatedGaiaIdFetchSuccess(
39 const std::string& access_token) {
40 LOG(INFO) << "*** GaiaFetcherDelegate::OnObfuscatedGaiaIdFetchSuccess"
41 << "- success, " << access_token << " ***";
42 delete this; // TODO: temp only, remove when part of outer class
43 }
44 virtual void OnObfuscatedGaiaIdFetchFailure(
45 const GoogleServiceAuthError& error) {
46 LOG(INFO) << "*** GaiaFetcherDelegate::OnObfuscatedGaiaIdFetchFailure, "
47 << "error is " << (int) error.state() << " ***";
48 delete this; // TODO: temp only, remove when part of outer class
49 }
50
51 };
52
53 // free function to start the fetch operation
54 void StartGaiaIdFetch(Profile* profile) {
55 // TODO: Not for checkin, just for testing, remove all this before checkin
56 // LOG(INFO) << "*** PushMessagingEventRouter::Init called ***";
57 TokenService* token_service = TokenServiceFactory::GetForProfile(profile);
58 net::URLRequestContextGetter* context = profile->GetRequestContext();
59 const std::string refreshToken = token_service->GetOAuth2LoginRefreshToken();
60 GaiaFetcherDelegate* delegate = new GaiaFetcherDelegate();
61 std::vector<std::string> scopes;
62 scopes.push_back(
63 "https://www.googleapis.com/auth/chromewebstore.notification");
Munjal (Google) 2012/08/15 20:15:44 Put this scope in ObfuscatedGaiaIdFetcher class in
64 // TODO: Don't forget to manage the lifetime of the fetcher object
65 ObfuscatedGaiaIdFetcher* fetcher =
66 new ObfuscatedGaiaIdFetcher(context, delegate, refreshToken, scopes);
67 fetcher->Start();
68 // LOG(INFO) << "*** PushMessagingEventRouter::Init exiting ***";
69 }
70
26 void PushMessagingEventRouter::Init() { 71 void PushMessagingEventRouter::Init() {
27 // TODO(dcheng): Add hooks into InvalidationHandler when landed. 72 // TODO(dcheng): Add hooks into InvalidationHandler when landed.
73
74 // TODO: remove this and do it the right way before checkin
75 MessageLoop::current()->PostDelayedTask(
76 FROM_HERE,
77 base::Bind(&StartGaiaIdFetch, profile_),
78 base::TimeDelta::FromMilliseconds(2000));
79
80
28 } 81 }
29 82
30 void PushMessagingEventRouter::OnMessage(const std::string& extension_id, 83 void PushMessagingEventRouter::OnMessage(const std::string& extension_id,
31 int subchannel, 84 int subchannel,
32 const std::string& payload) { 85 const std::string& payload) {
33 glue::Message message; 86 glue::Message message;
34 message.subchannel_id = subchannel; 87 message.subchannel_id = subchannel;
35 message.payload = payload; 88 message.payload = payload;
36 89
37 scoped_ptr<base::Value> parameters(glue::OnMessage::Create(message)); 90 scoped_ptr<base::Value> parameters(glue::OnMessage::Create(message));
38 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 91 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
39 extension_id, 92 extension_id,
40 event_names::kOnPushMessage, 93 event_names::kOnPushMessage,
41 *parameters.get(), 94 *parameters.get(),
42 profile_, 95 profile_,
43 GURL()); 96 GURL());
44 } 97 }
45 98
46 } // namespace extensions 99 } // namespace extensions
Munjal (Google) 2012/08/15 20:15:44 This file has a bunch of LOG statements which are
Pete Williamson 2012/08/15 22:02:29 Hmm, this looks like an older version of the file.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698