OLD | NEW |
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/chromeos/gdata/operations_base.h" | 5 #include "chrome/browser/chromeos/gdata/operations_base.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 } // namespace | 77 } // namespace |
78 | 78 |
79 namespace gdata { | 79 namespace gdata { |
80 | 80 |
81 //================================ AuthOperation =============================== | 81 //================================ AuthOperation =============================== |
82 | 82 |
83 AuthOperation::AuthOperation(GDataOperationRegistry* registry, | 83 AuthOperation::AuthOperation(GDataOperationRegistry* registry, |
84 Profile* profile, | |
85 const AuthStatusCallback& callback, | 84 const AuthStatusCallback& callback, |
86 const std::string& refresh_token) | 85 const std::string& refresh_token) |
87 : GDataOperationRegistry::Operation(registry), | 86 : GDataOperationRegistry::Operation(registry), |
88 profile_(profile), refresh_token_(refresh_token), callback_(callback) { | 87 refresh_token_(refresh_token), callback_(callback) { |
89 } | 88 } |
90 | 89 |
91 AuthOperation::~AuthOperation() {} | 90 AuthOperation::~AuthOperation() {} |
92 | 91 |
93 void AuthOperation::Start() { | 92 void AuthOperation::Start() { |
94 DCHECK(!refresh_token_.empty()); | 93 DCHECK(!refresh_token_.empty()); |
95 std::vector<std::string> scopes; | 94 std::vector<std::string> scopes; |
96 scopes.push_back(kDocsListScope); | 95 scopes.push_back(kDocsListScope); |
97 scopes.push_back(kSpreadsheetsScope); | 96 scopes.push_back(kSpreadsheetsScope); |
98 scopes.push_back(kUserContentScope); | 97 scopes.push_back(kUserContentScope); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", | 147 UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", |
149 kSuccessRatioHistogramFailure, | 148 kSuccessRatioHistogramFailure, |
150 kSuccessRatioHistogramMaxValue); | 149 kSuccessRatioHistogramMaxValue); |
151 callback_.Run(HTTP_UNAUTHORIZED, std::string()); | 150 callback_.Run(HTTP_UNAUTHORIZED, std::string()); |
152 } | 151 } |
153 NotifyFinish(GDataOperationRegistry::OPERATION_FAILED); | 152 NotifyFinish(GDataOperationRegistry::OPERATION_FAILED); |
154 } | 153 } |
155 | 154 |
156 //============================ UrlFetchOperationBase =========================== | 155 //============================ UrlFetchOperationBase =========================== |
157 | 156 |
158 UrlFetchOperationBase::UrlFetchOperationBase(GDataOperationRegistry* registry, | 157 UrlFetchOperationBase::UrlFetchOperationBase(GDataOperationRegistry* registry) |
159 Profile* profile) | |
160 : GDataOperationRegistry::Operation(registry), | 158 : GDataOperationRegistry::Operation(registry), |
161 profile_(profile), | |
162 re_authenticate_count_(0), | 159 re_authenticate_count_(0), |
163 save_temp_file_(false), | 160 save_temp_file_(false), |
164 started_(false) { | 161 started_(false) { |
165 } | 162 } |
166 | 163 |
167 UrlFetchOperationBase::UrlFetchOperationBase( | 164 UrlFetchOperationBase::UrlFetchOperationBase( |
168 GDataOperationRegistry* registry, | 165 GDataOperationRegistry* registry, |
169 GDataOperationRegistry::OperationType type, | 166 GDataOperationRegistry::OperationType type, |
170 const FilePath& path, | 167 const FilePath& path) |
171 Profile* profile) | |
172 : GDataOperationRegistry::Operation(registry, type, path), | 168 : GDataOperationRegistry::Operation(registry, type, path), |
173 profile_(profile), | |
174 re_authenticate_count_(0), | 169 re_authenticate_count_(0), |
175 save_temp_file_(false) { | 170 save_temp_file_(false) { |
176 } | 171 } |
177 | 172 |
178 UrlFetchOperationBase::~UrlFetchOperationBase() {} | 173 UrlFetchOperationBase::~UrlFetchOperationBase() {} |
179 | 174 |
180 void UrlFetchOperationBase::Start(const std::string& auth_token) { | 175 void UrlFetchOperationBase::Start(const std::string& auth_token) { |
181 DCHECK(!auth_token.empty()); | 176 DCHECK(!auth_token.empty()); |
182 | 177 |
183 GURL url = GetURL(); | 178 GURL url = GetURL(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 headers.assign("Response headers are malformed!!"); | 323 headers.assign("Response headers are malformed!!"); |
329 } else { | 324 } else { |
330 url_fetcher->GetResponseHeaders()->GetNormalizedHeaders(&headers); | 325 url_fetcher->GetResponseHeaders()->GetNormalizedHeaders(&headers); |
331 } | 326 } |
332 return headers; | 327 return headers; |
333 } | 328 } |
334 | 329 |
335 //============================ EntryActionOperation ============================ | 330 //============================ EntryActionOperation ============================ |
336 | 331 |
337 EntryActionOperation::EntryActionOperation(GDataOperationRegistry* registry, | 332 EntryActionOperation::EntryActionOperation(GDataOperationRegistry* registry, |
338 Profile* profile, | |
339 const EntryActionCallback& callback, | 333 const EntryActionCallback& callback, |
340 const GURL& document_url) | 334 const GURL& document_url) |
341 : UrlFetchOperationBase(registry, profile), | 335 : UrlFetchOperationBase(registry), |
342 callback_(callback), | 336 callback_(callback), |
343 document_url_(document_url) { | 337 document_url_(document_url) { |
344 } | 338 } |
345 | 339 |
346 EntryActionOperation::~EntryActionOperation() {} | 340 EntryActionOperation::~EntryActionOperation() {} |
347 | 341 |
348 void EntryActionOperation::ProcessURLFetchResults(const URLFetcher* source) { | 342 void EntryActionOperation::ProcessURLFetchResults(const URLFetcher* source) { |
349 if (!callback_.is_null()) { | 343 if (!callback_.is_null()) { |
350 GDataErrorCode code = GetErrorCode(source); | 344 GDataErrorCode code = GetErrorCode(source); |
351 callback_.Run(code, document_url_); | 345 callback_.Run(code, document_url_); |
352 } | 346 } |
353 const bool success = true; | 347 const bool success = true; |
354 OnProcessURLFetchResultsComplete(success); | 348 OnProcessURLFetchResultsComplete(success); |
355 } | 349 } |
356 | 350 |
357 void EntryActionOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { | 351 void EntryActionOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { |
358 if (!callback_.is_null()) | 352 if (!callback_.is_null()) |
359 callback_.Run(code, document_url_); | 353 callback_.Run(code, document_url_); |
360 } | 354 } |
361 | 355 |
362 //============================== GetDataOperation ============================== | 356 //============================== GetDataOperation ============================== |
363 | 357 |
364 GetDataOperation::GetDataOperation(GDataOperationRegistry* registry, | 358 GetDataOperation::GetDataOperation(GDataOperationRegistry* registry, |
365 Profile* profile, | |
366 const GetDataCallback& callback) | 359 const GetDataCallback& callback) |
367 : UrlFetchOperationBase(registry, profile), | 360 : UrlFetchOperationBase(registry), |
368 callback_(callback), | 361 callback_(callback), |
369 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 362 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
370 } | 363 } |
371 | 364 |
372 GetDataOperation::~GetDataOperation() {} | 365 GetDataOperation::~GetDataOperation() {} |
373 | 366 |
374 void GetDataOperation::ProcessURLFetchResults(const URLFetcher* source) { | 367 void GetDataOperation::ProcessURLFetchResults(const URLFetcher* source) { |
375 std::string data; | 368 std::string data; |
376 source->GetResponseAsString(&data); | 369 source->GetResponseAsString(&data); |
377 scoped_ptr<base::Value> root_value; | 370 scoped_ptr<base::Value> root_value; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 success = false; | 422 success = false; |
430 } | 423 } |
431 | 424 |
432 // The ownership of the parsed json object is transfered to RunCallBack(), | 425 // The ownership of the parsed json object is transfered to RunCallBack(), |
433 // keeping the ownership of the |value| here. | 426 // keeping the ownership of the |value| here. |
434 RunCallback(fetch_error_code, value->Pass()); | 427 RunCallback(fetch_error_code, value->Pass()); |
435 | 428 |
436 DCHECK(!value->get()); | 429 DCHECK(!value->get()); |
437 | 430 |
438 OnProcessURLFetchResultsComplete(success); | 431 OnProcessURLFetchResultsComplete(success); |
439 // |value| will be deleted after return beause it is base::Owned()'d. | 432 // |value| will be deleted after return because it is base::Owned()'d. |
440 } | 433 } |
441 | 434 |
442 void GetDataOperation::RunCallback(GDataErrorCode fetch_error_code, | 435 void GetDataOperation::RunCallback(GDataErrorCode fetch_error_code, |
443 scoped_ptr<base::Value> value) { | 436 scoped_ptr<base::Value> value) { |
444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
445 if (!callback_.is_null()) | 438 if (!callback_.is_null()) |
446 callback_.Run(fetch_error_code, value.Pass()); | 439 callback_.Run(fetch_error_code, value.Pass()); |
447 } | 440 } |
448 | 441 |
449 } // namespace gdata | 442 } // namespace gdata |
OLD | NEW |