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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 if (open_with_links[i].app_id == app_id) { | 139 if (open_with_links[i].app_id == app_id) { |
143 callback.Run(HTTP_SUCCESS, open_with_links[i].open_url); | 140 callback.Run(HTTP_SUCCESS, open_with_links[i].open_url); |
144 return; | 141 return; |
145 } | 142 } |
146 } | 143 } |
147 | 144 |
148 // Not found. | 145 // Not found. |
149 callback.Run(GDATA_OTHER_ERROR, GURL()); | 146 callback.Run(GDATA_OTHER_ERROR, GURL()); |
150 } | 147 } |
151 | 148 |
| 149 void ExtractShareUrlAndRun(const google_apis::GetShareUrlCallback& callback, |
| 150 google_apis::GDataErrorCode error, |
| 151 scoped_ptr<google_apis::ResourceEntry> entry) { |
| 152 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 153 |
| 154 const google_apis::Link* share_link = |
| 155 entry ? entry->GetLinkByType(google_apis::Link::LINK_SHARE) : NULL; |
| 156 callback.Run(error, share_link ? share_link->href() : GURL()); |
| 157 } |
| 158 |
152 // Ignores the |entry|, and runs the |callback|. | 159 // Ignores the |entry|, and runs the |callback|. |
153 void EntryActionCallbackAdapter( | 160 void EntryActionCallbackAdapter( |
154 const EntryActionCallback& callback, | 161 const EntryActionCallback& callback, |
155 GDataErrorCode error, scoped_ptr<FileResource> entry) { | 162 GDataErrorCode error, scoped_ptr<FileResource> entry) { |
156 callback.Run(error); | 163 callback.Run(error); |
157 } | 164 } |
158 | 165 |
159 // The resource ID for the root directory for Drive API is defined in the spec: | 166 // The resource ID for the root directory for Drive API is defined in the spec: |
160 // https://developers.google.com/drive/folder | 167 // https://developers.google.com/drive/folder |
161 const char kDriveApiRootDirectoryResourceId[] = "root"; | 168 const char kDriveApiRootDirectoryResourceId[] = "root"; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 376 |
370 // Unfortunately "share url" is not yet supported on Drive API v2. | 377 // Unfortunately "share url" is not yet supported on Drive API v2. |
371 // So, as a fallback, we use GData WAPI protocol for this method. | 378 // So, as a fallback, we use GData WAPI protocol for this method. |
372 // TODO(hidehiko): Get rid of this implementation when share url is | 379 // TODO(hidehiko): Get rid of this implementation when share url is |
373 // supported on Drive API v2. | 380 // supported on Drive API v2. |
374 return sender_->StartRequestWithRetry( | 381 return sender_->StartRequestWithRetry( |
375 new GetResourceEntryRequest(sender_.get(), | 382 new GetResourceEntryRequest(sender_.get(), |
376 wapi_url_generator_, | 383 wapi_url_generator_, |
377 resource_id, | 384 resource_id, |
378 embed_origin, | 385 embed_origin, |
379 base::Bind(&util::ParseShareUrlAndRun, | 386 base::Bind(&ExtractShareUrlAndRun, |
380 callback))); | 387 callback))); |
381 } | 388 } |
382 | 389 |
383 CancelCallback DriveAPIService::GetAboutResource( | 390 CancelCallback DriveAPIService::GetAboutResource( |
384 const AboutResourceCallback& callback) { | 391 const AboutResourceCallback& callback) { |
385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 392 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
386 DCHECK(!callback.is_null()); | 393 DCHECK(!callback.is_null()); |
387 | 394 |
388 AboutGetRequest* request = | 395 AboutGetRequest* request = |
389 new AboutGetRequest(sender_.get(), url_generator_, callback); | 396 new AboutGetRequest(sender_.get(), url_generator_, callback); |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 if (CanSendRequest()) { | 741 if (CanSendRequest()) { |
735 FOR_EACH_OBSERVER( | 742 FOR_EACH_OBSERVER( |
736 DriveServiceObserver, observers_, OnReadyToSendRequests()); | 743 DriveServiceObserver, observers_, OnReadyToSendRequests()); |
737 } else if (!HasRefreshToken()) { | 744 } else if (!HasRefreshToken()) { |
738 FOR_EACH_OBSERVER( | 745 FOR_EACH_OBSERVER( |
739 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); | 746 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); |
740 } | 747 } |
741 } | 748 } |
742 | 749 |
743 } // namespace drive | 750 } // namespace drive |
OLD | NEW |