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

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: More style fixes per Munjal and DCheng 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/signin/token_service.h"
13 #include "chrome/browser/signin/token_service_factory.h"
12 #include "chrome/common/extensions/api/experimental_push_messaging.h" 14 #include "chrome/common/extensions/api/experimental_push_messaging.h"
13 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
14 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
17 #include "chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetche r.h"
18
19 using content::BrowserThread;
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() {}
(...skipping 11 matching lines...) Expand all
36 41
37 scoped_ptr<base::ListValue> args(glue::OnMessage::Create(message)); 42 scoped_ptr<base::ListValue> args(glue::OnMessage::Create(message));
38 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 43 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
39 extension_id, 44 extension_id,
40 event_names::kOnPushMessage, 45 event_names::kOnPushMessage,
41 args.Pass(), 46 args.Pass(),
42 profile_, 47 profile_,
43 GURL()); 48 GURL());
44 } 49 }
45 50
51 PushMessagingGetChannelIdFunction::PushMessagingGetChannelIdFunction() {}
52
53 PushMessagingGetChannelIdFunction::~PushMessagingGetChannelIdFunction() {}
54
55 bool PushMessagingGetChannelIdFunction::RunImpl() {
56 // Start the async fetch of the GAIA ID.
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
58 net::URLRequestContextGetter* context = profile()->GetRequestContext();
59 TokenService* token_service = TokenServiceFactory::GetForProfile(profile());
60 const std::string& refresh_token =
61 token_service->GetOAuth2LoginRefreshToken();
62 fetcher_.reset(new ObfuscatedGaiaIdFetcher(context, this, refresh_token));
63
64 // Balanced in ReportResult()
65 AddRef();
66
67 fetcher_->Start();
68
69 // Will finish asynchronously.
70 return true;
71 }
72
73 void PushMessagingGetChannelIdFunction::ReportResult(
74 const std::string& gaia_id, long status) {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
76 // Unpack the status and GaiaId parameters, and use it to build the
77 // channel ID here.
78 std::string channel_id(gaia_id);
79 if (!gaia_id.empty()) {
80 channel_id += ".";
81 channel_id += extension_id();
82 } else if (status != 0) {
dcheng 2012/08/20 22:52:22 That means if gaia_id is empty and status is zero
Pete Williamson 2012/08/20 23:19:28 != was supposed to be ==, changed.
83 status = GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS;
84 }
85
86 // TODO(petewil): It may be a good idea to further
87 // obfuscate the channel ID to prevent the user's obfuscated GAIA ID
88 // from being readily obtained. Security review will tell us if we need to.
89
90 // Create a ChannelId results object and set the fields.
91 glue::ChannelIdResult result;
92 result.channel_id = channel_id;
93 result.status = status;
94 results_ = glue::GetChannelId::Results::Create(result);
95 SendResponse(true);
96
97 // Balanced in RunImpl
98 Release();
99 }
100
101 void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchSuccess(
102 const std::string& gaia_id) {
103 ReportResult(gaia_id, 0);
104 }
105
106 void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchFailure(
107 const GoogleServiceAuthError& error) {
108 ReportResult(std::string(), error.state());
109 }
110
46 } // namespace extensions 111 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698