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

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: rebase to master 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"
dcheng 2012/08/16 19:12:43 Remove this include since it's not used.
Pete Williamson 2012/08/19 22:05:14 Done.
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"
dcheng 2012/08/16 19:12:43 Remove this include as it's not used.
Pete Williamson 2012/08/19 22:05:14 Done.
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 "chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetche r.h"
20
21 using content::BrowserThread;
15 22
16 namespace extensions { 23 namespace extensions {
17 24
18 namespace glue = extensions::api::experimental_push_messaging; 25 namespace glue = extensions::api::experimental_push_messaging;
19 26
20 PushMessagingEventRouter::PushMessagingEventRouter(Profile* profile) 27 PushMessagingEventRouter::PushMessagingEventRouter(Profile* profile)
21 : profile_(profile) { 28 : profile_(profile) {
22 } 29 }
23 30
24 PushMessagingEventRouter::~PushMessagingEventRouter() {} 31 PushMessagingEventRouter::~PushMessagingEventRouter() {}
(...skipping 11 matching lines...) Expand all
36 43
37 scoped_ptr<base::ListValue> args(glue::OnMessage::Create(message)); 44 scoped_ptr<base::ListValue> args(glue::OnMessage::Create(message));
38 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 45 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
39 extension_id, 46 extension_id,
40 event_names::kOnPushMessage, 47 event_names::kOnPushMessage,
41 args.Pass(), 48 args.Pass(),
42 profile_, 49 profile_,
43 GURL()); 50 GURL());
44 } 51 }
45 52
53 PushMessagingGetChannelIdFunction::PushMessagingGetChannelIdFunction() {}
54
55 PushMessagingGetChannelIdFunction::~PushMessagingGetChannelIdFunction() {}
56
57 bool PushMessagingGetChannelIdFunction::RunImpl() {
58
Munjal (Google) 2012/08/15 23:04:19 Nit: remove unnecessary empty lines. Here and ever
Pete Williamson 2012/08/19 22:05:14 Done, but you and I have different ideas of where
59 // Start the async fetch of the GAIA ID.
60 StartGaiaIdFetch(profile());
61
62 // Will finish asynchronously.
63 return true;
64 }
65
66 void PushMessagingGetChannelIdFunction::RespondOnUIThread(
Munjal (Google) 2012/08/15 23:04:19 Isn't the ObfuscatedGaiaIdFetcher already running
Pete Williamson 2012/08/20 18:38:42 Done.
67 const std::string& gaia_id, const long status) {
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
69
70 // Unpack the status and GaiaId parameters, and use it to build the
71 // channel ID here.
72 std::string channel_id = gaia_id + "." + extension_id();
Munjal (Google) 2012/08/15 23:04:19 NIt: Use StringPrintf?
dcheng 2012/08/16 19:12:43 Shouldn't channel ID be empty if gaia_id is empty?
Pete Williamson 2012/08/19 22:05:14 Good catch! Added check for empty
Pete Williamson 2012/08/19 22:05:14 I apologize for the pushback, but why? (While I'm
dcheng 2012/08/19 22:38:35 Chaining + results in multiple temporaries being c
Pete Williamson 2012/08/20 18:38:42 Done.
73
74 // TODO: (after initial checkin) It may be a good idea to further
75 // obfuscate the channel ID to prevent the user's obfuscated GAIA ID
76 // from being readily obtained. Security review will tell us if we need to.
77
78 // Create a status object and set the fields.
79 DictionaryValue* result = new DictionaryValue();
dcheng 2012/08/16 19:12:43 scoped_ptr
Pete Williamson 2012/08/19 22:05:14 I tried originally, and that failed to properly tr
dcheng 2012/08/19 22:38:35 Use scoped_ptr<T>::release() to transfer ownership
dcheng 2012/08/19 22:45:15 Some examples of using the IDL glue: http://code.g
Pete Williamson 2012/08/20 18:38:42 Done. Ah, I see that we are using chrome's scoped
80 result->SetString("channelId", channel_id);
81 result->SetDouble("status", status);
82
83 // SetResult() takes ownership of result.
dcheng 2012/08/16 19:12:43 If you use scoped_ptr, this comment won't be neede
Pete Williamson 2012/08/19 22:05:14 scoped_ptr doesn't work here because the object ne
84 SetResult(result);
85 SendResponse(true);
86 }
87
88 // Member function to start the fetch operation.
89 // This must be called on the UI thread.
90 void PushMessagingGetChannelIdFunction::StartGaiaIdFetch(
91 Profile* profile) {
Munjal (Google) 2012/08/15 23:04:19 You don't need to pass the profile here since it i
Pete Williamson 2012/08/19 22:05:14 Done.
92
93 TokenService* token_service = TokenServiceFactory::GetForProfile(profile);
94 net::URLRequestContextGetter* context = profile->GetRequestContext();
95 const std::string refresh_token =
Munjal (Google) 2012/08/15 23:04:19 const std::string& refresh_token
Pete Williamson 2012/08/19 22:05:14 Done.
96 token_service->GetOAuth2LoginRefreshToken();
97
98 // The fetcher deletes itself when the operation completes.
99 // It holds an addref to this class, which it releases when it deletes itself.
100 fetcher_ = new ObfuscatedGaiaIdFetcher(context, this, refresh_token);
101 fetcher_->Start();
102 }
103
104 void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchSuccess(
105 const std::string& gaia_id) {
Munjal (Google) 2012/08/15 23:04:19 Indentation: 4 spaces
Pete Williamson 2012/08/19 22:05:14 Done.
106
dcheng 2012/08/15 22:20:45 Extra new line. With 80 chars, vertical space is a
Pete Williamson 2012/08/19 22:05:14 Done, but I'm not sure that I agree in principle.
dcheng 2012/08/19 22:38:35 It's OK to have newlines to break up logical block
107 // Post the task over to the UI thread to return to JS.
108 // This also holds a reference on this class to keep it alive for a callback.
dcheng 2012/08/15 22:20:45 These two lines (and several other places) just de
Pete Williamson 2012/08/19 22:05:14 Comment changed, see if the new one is better.
dcheng 2012/08/19 22:38:35 You can remove the comment on line 104 entirely. b
Pete Williamson 2012/08/20 18:38:42 Done.
109 bool rv = BrowserThread::PostTask(
110 BrowserThread::UI, FROM_HERE,
111 base::Bind(
112 &PushMessagingGetChannelIdFunction::RespondOnUIThread,
113 this, gaia_id, 0));
114 DCHECK(rv);
115
Munjal (Google) 2012/08/15 23:04:19 nit: remove empty line. Same below.
Pete Williamson 2012/08/19 22:05:14 Done.
116 }
117
118 void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchFailure(
119 const GoogleServiceAuthError& error) {
120 // Post the task over to the UI thread to return to JS.
121 // This also holds a reference on this class to keep it alive for a callback.
122 bool rv = BrowserThread::PostTask(
123 BrowserThread::IO, FROM_HERE,
124 base::Bind(
125 &PushMessagingGetChannelIdFunction::RespondOnUIThread,
126 this, "", error.state()));
dcheng 2012/08/16 19:12:43 std::string() instead of ""
Pete Williamson 2012/08/19 22:05:14 Done.
127 DCHECK(rv);
128
129 }
130
46 } // namespace extensions 131 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698