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/gdata_operations.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_operations.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" | |
14 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 13 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
15 #include "chrome/common/net/gaia/gaia_urls.h" | 14 #include "chrome/common/net/gaia/gaia_urls.h" |
16 #include "chrome/common/net/gaia/google_service_auth_error.h" | 15 #include "chrome/common/net/gaia/google_service_auth_error.h" |
17 #include "chrome/common/net/url_util.h" | 16 #include "chrome/common/net/url_util.h" |
18 #include "net/base/escape.h" | 17 #include "net/base/escape.h" |
19 #include "net/http/http_util.h" | 18 #include "net/http/http_util.h" |
20 #include "net/url_request/url_fetcher.h" | 19 #include "net/url_request/url_fetcher.h" |
21 #include "net/url_request/url_request_status.h" | 20 #include "net/url_request/url_request_status.h" |
22 #include "third_party/libxml/chromium/libxml_utils.h" | 21 #include "third_party/libxml/chromium/libxml_utils.h" |
23 | 22 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 "https://docs.google.com/feeds/default/private/full"; | 60 "https://docs.google.com/feeds/default/private/full"; |
62 | 61 |
63 // URL requesting single document entry whose resource id is specified by "%s". | 62 // URL requesting single document entry whose resource id is specified by "%s". |
64 const char kGetDocumentEntryURLFormat[] = | 63 const char kGetDocumentEntryURLFormat[] = |
65 "https://docs.google.com/feeds/default/private/full/%s"; | 64 "https://docs.google.com/feeds/default/private/full/%s"; |
66 | 65 |
67 // Metadata feed with things like user quota. | 66 // Metadata feed with things like user quota. |
68 const char kAccountMetadataURL[] = | 67 const char kAccountMetadataURL[] = |
69 "https://docs.google.com/feeds/metadata/default"; | 68 "https://docs.google.com/feeds/metadata/default"; |
70 | 69 |
| 70 const char kDriveV2AboutURL[] = |
| 71 "https://www.googleapis.com/drive/v2/about"; |
| 72 |
71 const char kUploadContentRange[] = "Content-Range: bytes "; | 73 const char kUploadContentRange[] = "Content-Range: bytes "; |
72 const char kUploadContentType[] = "X-Upload-Content-Type: "; | 74 const char kUploadContentType[] = "X-Upload-Content-Type: "; |
73 const char kUploadContentLength[] = "X-Upload-Content-Length: "; | 75 const char kUploadContentLength[] = "X-Upload-Content-Length: "; |
74 | 76 |
75 #ifndef NDEBUG | 77 #ifndef NDEBUG |
76 // Use smaller 'page' size while debugging to ensure we hit feed reload | 78 // Use smaller 'page' size while debugging to ensure we hit feed reload |
77 // almost always. Be careful not to use something too small on account that | 79 // almost always. Be careful not to use something too small on account that |
78 // have many items because server side 503 error might kick in. | 80 // have many items because server side 503 error might kick in. |
79 const int kMaxDocumentsPerFeed = 1000; | 81 const int kMaxDocumentsPerFeed = 1000; |
80 #else | 82 #else |
81 const int kMaxDocumentsPerFeed = 1000; | 83 const int kMaxDocumentsPerFeed = 1000; |
82 #endif | 84 #endif |
83 | 85 |
84 // Maximum number of attempts for re-authentication per operation. | 86 // Maximum number of attempts for re-authentication per operation. |
85 const int kMaxReAuthenticateAttemptsPerOperation = 1; | 87 const int kMaxReAuthenticateAttemptsPerOperation = 1; |
86 | 88 |
87 const char kFeedField[] = "feed"; | 89 const char kFeedField[] = "feed"; |
88 | 90 |
89 // Templates for file uploading. | 91 // Templates for file uploading. |
90 const char kUploadParamConvertKey[] = "convert"; | 92 const char kUploadParamConvertKey[] = "convert"; |
91 const char kUploadParamConvertValue[] = "false"; | 93 const char kUploadParamConvertValue[] = "false"; |
92 const char kUploadResponseLocation[] = "location"; | 94 const char kUploadResponseLocation[] = "location"; |
93 const char kUploadResponseRange[] = "range"; | 95 const char kUploadResponseRange[] = "range"; |
94 | 96 |
95 // OAuth scope for the documents API. | 97 // OAuth scope for the documents API. |
96 const char kDocsListScope[] = "https://docs.google.com/feeds/"; | 98 const char kDocsListScope[] = "https://docs.google.com/feeds/"; |
97 const char kSpreadsheetsScope[] = "https://spreadsheets.google.com/feeds/"; | 99 const char kSpreadsheetsScope[] = "https://spreadsheets.google.com/feeds/"; |
98 const char kUserContentScope[] = "https://docs.googleusercontent.com/"; | 100 const char kUserContentScope[] = "https://docs.googleusercontent.com/"; |
99 | 101 |
| 102 // OAuth scope for Google Drive v2 API |
| 103 // See https://developers.google.com/drive/scopes. |
| 104 // Tokens with scope https://docs.google.com/feeds are accepted and treated |
| 105 // the same as tokens with scope https://www.googleapis.com/auth/drive and |
| 106 // this is not necessary for the migration period. |
| 107 const char kDriveScope[] = "https://www.googleapis.com/auth/drive"; |
| 108 |
100 // Adds additional parameters for API version, output content type and to show | 109 // Adds additional parameters for API version, output content type and to show |
101 // folders in the feed are added to document feed URLs. | 110 // folders in the feed are added to document feed URLs. |
102 GURL AddStandardUrlParams(const GURL& url) { | 111 GURL AddStandardUrlParams(const GURL& url) { |
103 GURL result = | 112 GURL result = |
104 chrome_common_net::AppendOrReplaceQueryParameter(url, "v", "3"); | 113 chrome_common_net::AppendOrReplaceQueryParameter(url, "v", "3"); |
105 result = | 114 result = |
106 chrome_common_net::AppendOrReplaceQueryParameter(result, "alt", "json"); | 115 chrome_common_net::AppendOrReplaceQueryParameter(result, "alt", "json"); |
107 return result; | 116 return result; |
108 } | 117 } |
109 | 118 |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 GURL result = GURL(base::StringPrintf(kGetDocumentEntryURLFormat, | 569 GURL result = GURL(base::StringPrintf(kGetDocumentEntryURLFormat, |
561 net::EscapePath(resource_id_).c_str())); | 570 net::EscapePath(resource_id_).c_str())); |
562 return AddStandardUrlParams(result); | 571 return AddStandardUrlParams(result); |
563 } | 572 } |
564 | 573 |
565 //========================= GetAccountMetadataOperation ======================== | 574 //========================= GetAccountMetadataOperation ======================== |
566 | 575 |
567 GetAccountMetadataOperation::GetAccountMetadataOperation( | 576 GetAccountMetadataOperation::GetAccountMetadataOperation( |
568 GDataOperationRegistry* registry, | 577 GDataOperationRegistry* registry, |
569 Profile* profile, | 578 Profile* profile, |
570 const GetDataCallback& callback) | 579 const GetDataCallback& callback, |
571 : GetDataOperation(registry, profile, callback) { | 580 bool use_drive_api) |
| 581 : GetDataOperation(registry, profile, callback), |
| 582 use_drive_api_(use_drive_api) { |
572 } | 583 } |
573 | 584 |
574 GetAccountMetadataOperation::~GetAccountMetadataOperation() {} | 585 GetAccountMetadataOperation::~GetAccountMetadataOperation() {} |
575 | 586 |
576 GURL GetAccountMetadataOperation::GetURL() const { | 587 GURL GetAccountMetadataOperation::GetURL() const { |
577 return AddMetadataUrlParams(GURL(kAccountMetadataURL)); | 588 return use_drive_api_ ? |
| 589 GURL(kDriveV2AboutURL) : AddMetadataUrlParams(GURL(kAccountMetadataURL)); |
578 } | 590 } |
579 | 591 |
580 //============================ DownloadFileOperation =========================== | 592 //============================ DownloadFileOperation =========================== |
581 | 593 |
582 DownloadFileOperation::DownloadFileOperation( | 594 DownloadFileOperation::DownloadFileOperation( |
583 GDataOperationRegistry* registry, | 595 GDataOperationRegistry* registry, |
584 Profile* profile, | 596 Profile* profile, |
585 const DownloadActionCallback& download_action_callback, | 597 const DownloadActionCallback& download_action_callback, |
586 const GetDownloadDataCallback& get_download_data_callback, | 598 const GetDownloadDataCallback& get_download_data_callback, |
587 const GURL& document_url, | 599 const GURL& document_url, |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 return true; | 1238 return true; |
1227 } | 1239 } |
1228 | 1240 |
1229 void ResumeUploadOperation::OnURLFetchUploadProgress( | 1241 void ResumeUploadOperation::OnURLFetchUploadProgress( |
1230 const net::URLFetcher* source, int64 current, int64 total) { | 1242 const net::URLFetcher* source, int64 current, int64 total) { |
1231 // Adjust the progress values according to the range currently uploaded. | 1243 // Adjust the progress values according to the range currently uploaded. |
1232 NotifyProgress(params_.start_range + current, params_.content_length); | 1244 NotifyProgress(params_.start_range + current, params_.content_length); |
1233 } | 1245 } |
1234 | 1246 |
1235 } // namespace gdata | 1247 } // namespace gdata |
OLD | NEW |