Chromium Code Reviews| 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/drive/drive_api_service.h" | 5 #include "chrome/browser/drive/drive_api_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/sequenced_task_runner.h" | |
| 12 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 13 #include "base/task_runner_util.h" | |
| 14 #include "base/values.h" | |
| 15 #include "chrome/browser/drive/drive_api_util.h" | 12 #include "chrome/browser/drive/drive_api_util.h" |
| 16 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 17 #include "google_apis/drive/auth_service.h" | 14 #include "google_apis/drive/auth_service.h" |
| 18 #include "google_apis/drive/drive_api_parser.h" | 15 #include "google_apis/drive/drive_api_parser.h" |
| 19 #include "google_apis/drive/drive_api_requests.h" | 16 #include "google_apis/drive/drive_api_requests.h" |
| 20 #include "google_apis/drive/gdata_errorcode.h" | 17 #include "google_apis/drive/gdata_errorcode.h" |
| 21 #include "google_apis/drive/gdata_wapi_parser.h" | 18 #include "google_apis/drive/gdata_wapi_parser.h" |
| 22 #include "google_apis/drive/gdata_wapi_requests.h" | 19 #include "google_apis/drive/gdata_wapi_requests.h" |
| 23 #include "google_apis/drive/request_sender.h" | 20 #include "google_apis/drive/request_sender.h" |
| 24 #include "google_apis/google_api_keys.h" | 21 #include "google_apis/google_api_keys.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 if (open_with_links[i].app_id == app_id) { | 137 if (open_with_links[i].app_id == app_id) { |
| 141 callback.Run(HTTP_SUCCESS, open_with_links[i].open_url); | 138 callback.Run(HTTP_SUCCESS, open_with_links[i].open_url); |
| 142 return; | 139 return; |
| 143 } | 140 } |
| 144 } | 141 } |
| 145 | 142 |
| 146 // Not found. | 143 // Not found. |
| 147 callback.Run(GDATA_OTHER_ERROR, GURL()); | 144 callback.Run(GDATA_OTHER_ERROR, GURL()); |
| 148 } | 145 } |
| 149 | 146 |
| 147 void ExtractShareUrlAndRun(const google_apis::GetShareUrlCallback& callback, | |
| 148 google_apis::GDataErrorCode error, | |
| 149 scoped_ptr<google_apis::ResourceEntry> entry) { | |
| 150 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 151 | |
| 152 const google_apis::Link* share_link = | |
| 153 entry ? entry->GetLinkByType(google_apis::Link::LINK_SHARE) : NULL; | |
| 154 callback.Run(error, share_link ? share_link->href() : GURL()); | |
| 155 } | |
| 156 | |
|
hashimoto
2014/08/07 02:55:09
nit: This blank line is redundant?
kinaba
2014/08/07 02:58:08
Done.
| |
| 157 | |
| 150 // Ignores the |entry|, and runs the |callback|. | 158 // Ignores the |entry|, and runs the |callback|. |
| 151 void EntryActionCallbackAdapter( | 159 void EntryActionCallbackAdapter( |
| 152 const EntryActionCallback& callback, | 160 const EntryActionCallback& callback, |
| 153 GDataErrorCode error, scoped_ptr<FileResource> entry) { | 161 GDataErrorCode error, scoped_ptr<FileResource> entry) { |
| 154 callback.Run(error); | 162 callback.Run(error); |
| 155 } | 163 } |
| 156 | 164 |
| 157 // The resource ID for the root directory for Drive API is defined in the spec: | 165 // The resource ID for the root directory for Drive API is defined in the spec: |
| 158 // https://developers.google.com/drive/folder | 166 // https://developers.google.com/drive/folder |
| 159 const char kDriveApiRootDirectoryResourceId[] = "root"; | 167 const char kDriveApiRootDirectoryResourceId[] = "root"; |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 | 373 |
| 366 // Unfortunately "share url" is not yet supported on Drive API v2. | 374 // Unfortunately "share url" is not yet supported on Drive API v2. |
| 367 // So, as a fallback, we use GData WAPI protocol for this method. | 375 // So, as a fallback, we use GData WAPI protocol for this method. |
| 368 // TODO(hidehiko): Get rid of this implementation when share url is | 376 // TODO(hidehiko): Get rid of this implementation when share url is |
| 369 // supported on Drive API v2. | 377 // supported on Drive API v2. |
| 370 return sender_->StartRequestWithRetry( | 378 return sender_->StartRequestWithRetry( |
| 371 new GetResourceEntryRequest(sender_.get(), | 379 new GetResourceEntryRequest(sender_.get(), |
| 372 wapi_url_generator_, | 380 wapi_url_generator_, |
| 373 resource_id, | 381 resource_id, |
| 374 embed_origin, | 382 embed_origin, |
| 375 base::Bind(&util::ParseShareUrlAndRun, | 383 base::Bind(&ExtractShareUrlAndRun, |
| 376 callback))); | 384 callback))); |
| 377 } | 385 } |
| 378 | 386 |
| 379 CancelCallback DriveAPIService::GetAboutResource( | 387 CancelCallback DriveAPIService::GetAboutResource( |
| 380 const AboutResourceCallback& callback) { | 388 const AboutResourceCallback& callback) { |
| 381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 382 DCHECK(!callback.is_null()); | 390 DCHECK(!callback.is_null()); |
| 383 | 391 |
| 384 AboutGetRequest* request = | 392 AboutGetRequest* request = |
| 385 new AboutGetRequest(sender_.get(), url_generator_, callback); | 393 new AboutGetRequest(sender_.get(), url_generator_, callback); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 if (CanSendRequest()) { | 754 if (CanSendRequest()) { |
| 747 FOR_EACH_OBSERVER( | 755 FOR_EACH_OBSERVER( |
| 748 DriveServiceObserver, observers_, OnReadyToSendRequests()); | 756 DriveServiceObserver, observers_, OnReadyToSendRequests()); |
| 749 } else if (!HasRefreshToken()) { | 757 } else if (!HasRefreshToken()) { |
| 750 FOR_EACH_OBSERVER( | 758 FOR_EACH_OBSERVER( |
| 751 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); | 759 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); |
| 752 } | 760 } |
| 753 } | 761 } |
| 754 | 762 |
| 755 } // namespace drive | 763 } // namespace drive |
| OLD | NEW |