OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/app_notify_channel_setup.h" | 5 #include "chrome/browser/extensions/app_notify_channel_setup.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 static const char kCWSChannelServiceURL[] = | 50 static const char kCWSChannelServiceURL[] = |
51 "https://www.googleapis.com/chromewebstore/" | 51 "https://www.googleapis.com/chromewebstore/" |
52 "v1.1/channels/id"; | 52 "v1.1/channels/id"; |
53 static const char* kRelevantGaiaServices[] = { | 53 static const char* kRelevantGaiaServices[] = { |
54 GaiaConstants::kCWSService, | 54 GaiaConstants::kCWSService, |
55 GaiaConstants::kLSOService, | 55 GaiaConstants::kLSOService, |
56 }; | 56 }; |
57 static const int kRelevantGaiaServicesCount = arraysize(kRelevantGaiaServices); | 57 static const int kRelevantGaiaServicesCount = arraysize(kRelevantGaiaServices); |
58 } // namespace. | 58 } // namespace. |
59 | 59 |
60 | |
Munjal (Google)
2011/11/29 21:55:34
Nit: remove extra newline.
asargent_no_longer_on_chrome
2011/11/30 06:06:20
Done.
I also added spaces around the namespace op
| |
61 static AppNotifyChannelSetup::InterceptorForTests* g_interceptor = NULL; | |
Munjal (Google)
2011/11/29 21:55:34
Would it make more sense for this to be in anonymo
asargent_no_longer_on_chrome
2011/11/30 06:06:20
Good idea - moved into the anonymous namespace abo
| |
62 | |
63 // static | |
64 void AppNotifyChannelSetup::SetInterceptorForTests( | |
65 AppNotifyChannelSetup::InterceptorForTests* interceptor) { | |
66 g_interceptor = interceptor; | |
Munjal (Google)
2011/11/29 21:55:34
Nit: should we check that g_interceptor is NULL to
asargent_no_longer_on_chrome
2011/11/30 06:06:20
Good idea, done.
| |
67 } | |
68 | |
60 AppNotifyChannelSetup::AppNotifyChannelSetup( | 69 AppNotifyChannelSetup::AppNotifyChannelSetup( |
61 Profile* profile, | 70 Profile* profile, |
62 const std::string& extension_id, | 71 const std::string& extension_id, |
63 const std::string& client_id, | 72 const std::string& client_id, |
64 const GURL& requestor_url, | 73 const GURL& requestor_url, |
65 int return_route_id, | 74 int return_route_id, |
66 int callback_id, | 75 int callback_id, |
67 AppNotifyChannelUI* ui, | 76 AppNotifyChannelUI* ui, |
68 base::WeakPtr<AppNotifyChannelSetup::Delegate> delegate) | 77 base::WeakPtr<AppNotifyChannelSetup::Delegate> delegate) |
69 : profile_(profile), | 78 : profile_(profile), |
70 extension_id_(extension_id), | 79 extension_id_(extension_id), |
71 client_id_(client_id), | 80 client_id_(client_id), |
72 requestor_url_(requestor_url), | 81 requestor_url_(requestor_url), |
73 return_route_id_(return_route_id), | 82 return_route_id_(return_route_id), |
74 callback_id_(callback_id), | 83 callback_id_(callback_id), |
75 delegate_(delegate), | 84 delegate_(delegate), |
76 ui_(ui), | 85 ui_(ui), |
77 state_(INITIAL), | 86 state_(INITIAL), |
78 fetch_token_success_count_(0), | 87 fetch_token_success_count_(0), |
79 fetch_token_fail_count_(0) {} | 88 fetch_token_fail_count_(0) {} |
80 | 89 |
81 AppNotifyChannelSetup::~AppNotifyChannelSetup() {} | 90 AppNotifyChannelSetup::~AppNotifyChannelSetup() {} |
82 | 91 |
83 void AppNotifyChannelSetup::Start() { | 92 void AppNotifyChannelSetup::Start() { |
93 if (g_interceptor) { | |
94 std::string channel_id; | |
95 std::string error; | |
96 g_interceptor->DoIntercept(this, &channel_id, &error); | |
97 delegate_->AppNotifyChannelSetupComplete(channel_id, error, this); | |
Munjal (Google)
2011/11/30 19:21:12
I am actually thinking if there is a way to avoid
asargent_no_longer_on_chrome
2011/11/30 19:45:21
Because this is used by a browser test, the entire
Munjal (Google)
2011/11/30 20:05:56
Thanks for the explanation. The interceptor approa
| |
98 return; | |
99 } | |
84 AddRef(); // Balanced in ReportResult. | 100 AddRef(); // Balanced in ReportResult. |
85 BeginLogin(); | 101 BeginLogin(); |
86 } | 102 } |
87 | 103 |
88 void AppNotifyChannelSetup::Observe( | 104 void AppNotifyChannelSetup::Observe( |
89 int type, | 105 int type, |
90 const content::NotificationSource& source, | 106 const content::NotificationSource& source, |
91 const content::NotificationDetails& details) { | 107 const content::NotificationDetails& details) { |
92 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { | 108 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { |
93 TokenService::TokenAvailableDetails* tok_details = | 109 TokenService::TokenAvailableDetails* tok_details = |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 } | 326 } |
311 } | 327 } |
312 | 328 |
313 void AppNotifyChannelSetup::ReportResult( | 329 void AppNotifyChannelSetup::ReportResult( |
314 const std::string& channel_id, | 330 const std::string& channel_id, |
315 const std::string& error) { | 331 const std::string& error) { |
316 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 332 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
317 CHECK(state_ == CHANNEL_ID_SETUP_DONE || state_ == ERROR_STATE); | 333 CHECK(state_ == CHANNEL_ID_SETUP_DONE || state_ == ERROR_STATE); |
318 | 334 |
319 if (delegate_.get()) { | 335 if (delegate_.get()) { |
320 delegate_->AppNotifyChannelSetupComplete( | 336 delegate_->AppNotifyChannelSetupComplete(channel_id, error, this); |
321 channel_id, error, return_route_id_, callback_id_); | |
322 } | 337 } |
323 Release(); // Matches AddRef in Start. | 338 Release(); // Matches AddRef in Start. |
324 } | 339 } |
325 | 340 |
326 // static | 341 // static |
327 GURL AppNotifyChannelSetup::GetCWSChannelServiceURL() { | 342 GURL AppNotifyChannelSetup::GetCWSChannelServiceURL() { |
328 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 343 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
329 if (command_line->HasSwitch(switches::kAppNotifyChannelServerURL)) { | 344 if (command_line->HasSwitch(switches::kAppNotifyChannelServerURL)) { |
330 std::string switch_value = command_line->GetSwitchValueASCII( | 345 std::string switch_value = command_line->GetSwitchValueASCII( |
331 switches::kAppNotifyChannelServerURL); | 346 switches::kAppNotifyChannelServerURL); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | 398 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
384 if (!dict->Get("id", &channel_id_value)) | 399 if (!dict->Get("id", &channel_id_value)) |
385 return false; | 400 return false; |
386 if (channel_id_value->GetType() != base::Value::TYPE_STRING) | 401 if (channel_id_value->GetType() != base::Value::TYPE_STRING) |
387 return false; | 402 return false; |
388 | 403 |
389 StringValue* channel_id = static_cast<StringValue*>(channel_id_value); | 404 StringValue* channel_id = static_cast<StringValue*>(channel_id_value); |
390 channel_id->GetAsString(result); | 405 channel_id->GetAsString(result); |
391 return true; | 406 return true; |
392 } | 407 } |
OLD | NEW |