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

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: 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) << "*** Obfuscated Gaia Id fetch returned success, "
41 << 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) << "*** Obfuscated Gaia Id fetch failed, error is "
47 << (int) error.state();
48 delete this; // TODO: temp only, remove when part of outer class
49 }
50
51 };
Munjal (Google) 2012/08/09 21:44:29 This seems like temporary code?
52
53 // free function to start the fetch operation
54 void StartGaiaIdFetch() {
55 // TODO: I really want to use the profile passed in, not get the last one
56 Profile* profile = ProfileManager::GetLastUsedProfile();
57 // TODO: Not for checkin, just for testing, remove all this before checkin
58 LOG(INFO) << "*** PushMessagingEventRouter::Init called ***";
59 TokenService* token_service = TokenServiceFactory::GetForProfile(profile);
60 net::URLRequestContextGetter* context = profile->GetRequestContext();
61 const std::string refreshToken = token_service->GetOAuth2LoginRefreshToken();
62 const std::string extensionId = "joginpnpfmplidoohnmocbdijkchphdm";
63 // TODO: we really want extensionId = ExtensionFunction::GetExtension()->id();
64 // but that in only available once we have a class inheriting
65 // from ExtensionFuction, which we will likely have later on
66 ObfuscatedGaiaIdFetcher::Parameters parameters(refreshToken, extensionId);
67 GaiaFetcherDelegate* delegate = new GaiaFetcherDelegate();
68 // TODO: Don't forget to manage the lifetime of the fetcher object
69 ObfuscatedGaiaIdFetcher* fetcher =
70 new ObfuscatedGaiaIdFetcher(context, delegate, parameters);
71 fetcher->Start();
72 LOG(INFO) << "*** PushMessagingEventRouter::Init exiting ***";
73 }
74
26 void PushMessagingEventRouter::Init() { 75 void PushMessagingEventRouter::Init() {
27 // TODO(dcheng): Add hooks into InvalidationHandler when landed. 76 // TODO(dcheng): Add hooks into InvalidationHandler when landed.
77
78 // MessageLoop::current()->PostDelayedTask(
79 // FROM_HERE,
80 // base::Bind(&StartGaiaIdFetch),
81 // base::TimeDelta::FromMilliseconds(2000));
82
83
28 } 84 }
Munjal (Google) 2012/08/09 21:44:29 Seems like all changes ot this file are done for t
29 85
30 void PushMessagingEventRouter::OnMessage(const std::string& extension_id, 86 void PushMessagingEventRouter::OnMessage(const std::string& extension_id,
31 int subchannel, 87 int subchannel,
32 const std::string& payload) { 88 const std::string& payload) {
33 glue::Message message; 89 glue::Message message;
34 message.subchannel_id = subchannel; 90 message.subchannel_id = subchannel;
35 message.payload = payload; 91 message.payload = payload;
36 92
37 scoped_ptr<base::Value> parameters(glue::OnMessage::Create(message)); 93 scoped_ptr<base::Value> parameters(glue::OnMessage::Create(message));
38 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 94 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
39 extension_id, 95 extension_id,
40 event_names::kOnPushMessage, 96 event_names::kOnPushMessage,
41 *parameters.get(), 97 *parameters.get(),
42 profile_, 98 profile_,
43 GURL()); 99 GURL());
44 } 100 }
45 101
46 } // namespace extensions 102 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698