15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 57d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/drive/gdata_wapi_service.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h" 119ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#include "base/message_loop/message_loop.h" 12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/sequenced_task_runner.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/values.h" 14eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "chrome/browser/drive/drive_api_util.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/browser_thread.h" 16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "google_apis/drive/auth_service.h" 17a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "google_apis/drive/drive_api_parser.h" 18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "google_apis/drive/gdata_errorcode.h" 19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "google_apis/drive/gdata_wapi_parser.h" 20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "google_apis/drive/gdata_wapi_requests.h" 21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "google_apis/drive/gdata_wapi_url_generator.h" 22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "google_apis/drive/request_sender.h" 234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "net/url_request/url_request_context_getter.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::BrowserThread; 26eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::AboutResource; 27424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)using google_apis::AboutResourceCallback; 28eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::AccountMetadata; 29eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::AddResourceToDirectoryRequest; 30eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::AppList; 31424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)using google_apis::AppListCallback; 32424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)using google_apis::AuthService; 337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochusing google_apis::AuthStatusCallback; 34eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::AuthorizeAppCallback; 35eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::AuthorizeAppRequest; 36eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::CancelCallback; 37eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::CreateDirectoryRequest; 38eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::DeleteResourceRequest; 39eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::DownloadActionCallback; 40eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::DownloadFileRequest; 41eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::EntryActionCallback; 42eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::GDATA_PARSE_ERROR; 43424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)using google_apis::GDataErrorCode; 44eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::GetAccountMetadataRequest; 45eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::GetContentCallback; 46eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::GetResourceEntryCallback; 47eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::GetResourceEntryRequest; 48eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::GetResourceListCallback; 49eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::GetResourceListRequest; 50bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdochusing google_apis::GetShareUrlCallback; 51eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::GetUploadStatusRequest; 52eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::HTTP_NOT_IMPLEMENTED; 53eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::InitiateUploadCallback; 54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::InitiateUploadExistingFileRequest; 55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::InitiateUploadNewFileRequest; 56bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdochusing google_apis::Link; 57eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::ProgressCallback; 58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::RemoveResourceFromDirectoryRequest; 59eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::RenameResourceRequest; 60eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::RequestSender; 61eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::ResourceEntry; 62eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::ResumeUploadRequest; 63eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::SearchByTitleRequest; 64eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing google_apis::UploadRangeCallback; 65eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 66eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochnamespace drive { 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// OAuth2 scopes for the documents API. 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kSpreadsheetsScope[] = "https://spreadsheets.google.com/feeds/"; 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kUserContentScope[] = "https://docs.googleusercontent.com/"; 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Parses the JSON value to ResourceEntry runs |callback|. 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ParseResourceEntryAndRun(const GetResourceEntryCallback& callback, 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GDataErrorCode error, 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<base::Value> value) { 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!value) { 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) callback.Run(error, scoped_ptr<ResourceEntry>()); 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Parsing ResourceEntry is cheap enough to do on UI thread. 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<ResourceEntry> entry = 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) google_apis::ResourceEntry::ExtractAndParse(*value); 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!entry) { 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) callback.Run(GDATA_PARSE_ERROR, scoped_ptr<ResourceEntry>()); 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) callback.Run(error, entry.Pass()); 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 96d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void ConvertAboutResourceAndRun( 97424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const AboutResourceCallback& callback, 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GDataErrorCode error, 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<AccountMetadata> account_metadata) { 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<AboutResource> about_resource; 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (account_metadata) { 105d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) about_resource = util::ConvertAccountMetadataToAboutResource( 10658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) *account_metadata, util::kWapiRootDirectoryResourceId); 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) callback.Run(error, about_resource.Pass()); 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 112d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void ConvertAppListAndRun( 113424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const AppListCallback& callback, 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GDataErrorCode error, 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<AccountMetadata> account_metadata) { 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<AppList> app_list; 120d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) if (account_metadata) 121d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) app_list = util::ConvertAccountMetadataToAppList(*account_metadata); 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) callback.Run(error, app_list.Pass()); 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)GDataWapiService::GDataWapiService( 129558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch OAuth2TokenService* oauth2_token_service, 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) net::URLRequestContextGetter* url_request_context_getter, 131f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) base::SequencedTaskRunner* blocking_task_runner, 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& base_url, 133eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const GURL& base_download_url, 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& custom_user_agent) 135558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch : oauth2_token_service_(oauth2_token_service), 136558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch url_request_context_getter_(url_request_context_getter), 137eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch blocking_task_runner_(blocking_task_runner), 138eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_(base_url, base_download_url), 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) custom_user_agent_(custom_user_agent) { 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GDataWapiService::~GDataWapiService() { 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 145868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (sender_.get()) 146868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) sender_->auth_service()->RemoveObserver(this); 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)void GDataWapiService::Initialize(const std::string& account_id) { 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<std::string> scopes; 153a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) scopes.push_back(util::kDocsListScope); 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scopes.push_back(kSpreadsheetsScope); 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scopes.push_back(kUserContentScope); 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Drive App scope is required for even WAPI v3 apps access. 157a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) scopes.push_back(util::kDriveAppsScope); 1589ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch sender_.reset(new RequestSender( 15968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) new AuthService(oauth2_token_service_, 16068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) account_id, 1614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) url_request_context_getter_.get(), 16268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) scopes), 1634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) url_request_context_getter_.get(), 1649ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch blocking_task_runner_.get(), 1659ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch custom_user_agent_)); 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 167868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) sender_->auth_service()->AddObserver(this); 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void GDataWapiService::AddObserver(DriveServiceObserver* observer) { 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observers_.AddObserver(observer); 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void GDataWapiService::RemoveObserver(DriveServiceObserver* observer) { 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observers_.RemoveObserver(observer); 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 178868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)bool GDataWapiService::CanSendRequest() const { 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return HasRefreshToken(); 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 184d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)ResourceIdCanonicalizer GDataWapiService::GetResourceIdCanonicalizer() const { 1858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return util::GetIdentityResourceIdCanonicalizer(); 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 188c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)std::string GDataWapiService::GetRootResourceId() const { 18958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return util::kWapiRootDirectoryResourceId; 190c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 191c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 192c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Because GData WAPI support is expected to be gone somehow soon by migration 193868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// to the Drive API v2, so we'll reuse GetResourceListRequest to implement 194868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// following methods, instead of cleaning the request class. 195c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::GetAllResourceList( 197c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const GetResourceListCallback& callback) { 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 199c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(!callback.is_null()); 200c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 202868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new GetResourceListRequest(sender_.get(), 203eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 204eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GURL(), // No override url 205eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 0, // start changestamp 206eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string(), // empty search query 207eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string(), // no directory resource id 208eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback)); 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::GetResourceListInDirectory( 212c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const std::string& directory_resource_id, 213c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const GetResourceListCallback& callback) { 214c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 215c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(!directory_resource_id.empty()); 216c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(!callback.is_null()); 217c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 219868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new GetResourceListRequest(sender_.get(), 220eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 221eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GURL(), // No override url 222eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 0, // start changestamp 223eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string(), // empty search query 224eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch directory_resource_id, 225eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback)); 226c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 227c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::Search( 2297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const std::string& search_query, 2307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const GetResourceListCallback& callback) { 231c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 232c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(!search_query.empty()); 233c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(!callback.is_null()); 234c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 236868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new GetResourceListRequest(sender_.get(), 237eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 238eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GURL(), // No override url 239eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 0, // start changestamp 240eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch search_query, 241eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string(), // no directory resource id 242eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback)); 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::SearchByTitle( 246c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const std::string& title, 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& directory_resource_id, 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GetResourceListCallback& callback) { 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 250c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(!title.empty()); 2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 254eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch new SearchByTitleRequest(sender_.get(), 255eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 256eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch title, 257eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch directory_resource_id, 258eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback)); 259c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 260c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::GetChangeList( 2627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) int64 start_changestamp, 2637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const GetResourceListCallback& callback) { 264c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 265c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DCHECK(!callback.is_null()); 266c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 268868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new GetResourceListRequest(sender_.get(), 269eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 270eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GURL(), // No override url 271eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch start_changestamp, 272eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string(), // empty search query 273eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string(), // no directory resource id 274eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback)); 275c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 276c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 277424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)CancelCallback GDataWapiService::GetRemainingChangeList( 27858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const GURL& next_link, 279424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const GetResourceListCallback& callback) { 280424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 28158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(!next_link.is_empty()); 282424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(!callback.is_null()); 283424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 28458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return GetRemainingResourceList(next_link, callback); 285424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 286424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 287424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)CancelCallback GDataWapiService::GetRemainingFileList( 28858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const GURL& next_link, 289424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const GetResourceListCallback& callback) { 290424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 29158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(!next_link.is_empty()); 292424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) DCHECK(!callback.is_null()); 293424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 29458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return GetRemainingResourceList(next_link, callback); 295424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 296424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 2977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::GetResourceEntry( 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& resource_id, 2992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GetResourceEntryCallback& callback) { 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 304eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch new GetResourceEntryRequest(sender_.get(), 305eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 306eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch resource_id, 307bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch GURL(), 308eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::Bind(&ParseResourceEntryAndRun, 309eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback))); 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 312bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben MurdochCancelCallback GDataWapiService::GetShareUrl( 313bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch const std::string& resource_id, 314bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch const GURL& embed_origin, 315bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch const GetShareUrlCallback& callback) { 316bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 317bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch DCHECK(!callback.is_null()); 318bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 319bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch return sender_->StartRequestWithRetry( 320bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch new GetResourceEntryRequest(sender_.get(), 321bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch url_generator_, 322bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch resource_id, 323bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch embed_origin, 324a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) base::Bind(&util::ParseShareUrlAndRun, 325bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch callback))); 326bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch} 327bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 3287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::GetAboutResource( 329424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const AboutResourceCallback& callback) { 3302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 334868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new GetAccountMetadataRequest( 335868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) sender_.get(), 3362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) url_generator_, 337d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) base::Bind(&ConvertAboutResourceAndRun, callback), 3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) false)); // Exclude installed apps. 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 341424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)CancelCallback GDataWapiService::GetAppList(const AppListCallback& callback) { 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 346eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch new GetAccountMetadataRequest(sender_.get(), 347eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 348d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) base::Bind(&ConvertAppListAndRun, callback), 349eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch true)); // Include installed apps. 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::DownloadFile( 3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& local_cache_path, 354eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const std::string& resource_id, 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const DownloadActionCallback& download_action_callback, 356c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const GetContentCallback& get_content_callback, 357c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const ProgressCallback& progress_callback) { 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!download_action_callback.is_null()); 360c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // get_content_callback and progress_callback may be null. 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 363868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new DownloadFileRequest(sender_.get(), 364eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 365868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) download_action_callback, 366868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) get_content_callback, 367868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) progress_callback, 368eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch resource_id, 369868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) local_cache_path)); 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::DeleteResource( 3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& resource_id, 3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& etag, 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const EntryActionCallback& callback) { 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 379d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) NOTIMPLEMENTED(); 380d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) callback.Run(google_apis::GDATA_OTHER_ERROR); 381d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) return CancelCallback(); 382d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles)} 383d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) 384d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles)CancelCallback GDataWapiService::TrashResource( 385d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) const std::string& resource_id, 386d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) const EntryActionCallback& callback) { 387d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 388d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) DCHECK(!callback.is_null()); 389d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) 390d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) const std::string empty_etag; 3917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 392868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new DeleteResourceRequest(sender_.get(), 393eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 394eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback, 395eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch resource_id, 396d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) empty_etag)); 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::AddNewDirectory( 4002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& parent_resource_id, 4017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const std::string& directory_title, 4022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GetResourceEntryCallback& callback) { 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 4042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 407868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new CreateDirectoryRequest(sender_.get(), 408eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 409eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::Bind(&ParseResourceEntryAndRun, 410eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback), 411eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch parent_resource_id, 4127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch directory_title)); 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::CopyResource( 41690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const std::string& resource_id, 41790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const std::string& parent_resource_id, 4187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const std::string& new_title, 41968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) const base::Time& last_modified, 42090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const GetResourceEntryCallback& callback) { 42190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 42290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DCHECK(!callback.is_null()); 42390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 42490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // GData WAPI doesn't support "copy" of regular files. 42590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // This method should never be called if GData WAPI is enabled. 42690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Instead, client code should download the file (if needed) and upload it. 42790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) NOTREACHED(); 4287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return CancelCallback(); 42990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 43090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 431f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)CancelCallback GDataWapiService::UpdateResource( 4323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const std::string& resource_id, 4333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const std::string& parent_resource_id, 4343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const std::string& new_title, 43568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) const base::Time& last_modified, 436f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const base::Time& last_viewed_by_me, 4373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const google_apis::GetResourceEntryCallback& callback) { 4383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 4393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DCHECK(!callback.is_null()); 4403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // GData WAPI doesn't support to "move" resources. 4423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // This method should never be called if GData WAPI is enabled. 4433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Instead, client code should rename the file, add new parent, and then 4443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // remove the old parent. 4453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) NOTREACHED(); 4463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return CancelCallback(); 4473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 4483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::RenameResource( 4502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& resource_id, 4517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const std::string& new_title, 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const EntryActionCallback& callback) { 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 4542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 457868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new RenameResourceRequest(sender_.get(), 458eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 459eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback, 460eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch resource_id, 4617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch new_title)); 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::AddResourceToDirectory( 4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& parent_resource_id, 4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& resource_id, 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const EntryActionCallback& callback) { 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 472868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new AddResourceToDirectoryRequest(sender_.get(), 473eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 474eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback, 475eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch parent_resource_id, 476eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch resource_id)); 4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::RemoveResourceFromDirectory( 4802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& parent_resource_id, 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& resource_id, 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const EntryActionCallback& callback) { 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 4842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 487868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new RemoveResourceFromDirectoryRequest(sender_.get(), 488eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 489eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback, 490eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch parent_resource_id, 491eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch resource_id)); 4922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::InitiateUploadNewFile( 4952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& content_type, 4962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int64 content_length, 4972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& parent_resource_id, 4982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& title, 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const InitiateUploadCallback& callback) { 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 5012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 5022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!parent_resource_id.empty()); 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 505868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new InitiateUploadNewFileRequest(sender_.get(), 506eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 507eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback, 508eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch content_type, 509eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch content_length, 510eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch parent_resource_id, 511eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch title)); 5122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::InitiateUploadExistingFile( 5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& content_type, 5162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int64 content_length, 5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& resource_id, 5182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& etag, 5192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const InitiateUploadCallback& callback) { 5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 5212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!resource_id.empty()); 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 525868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new InitiateUploadExistingFileRequest(sender_.get(), 526eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 527eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback, 528eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch content_type, 529eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch content_length, 530eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch resource_id, 531eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch etag)); 5322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::ResumeUpload( 5352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& upload_url, 5362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int64 start_position, 5372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int64 end_position, 5382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int64 content_length, 5392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& content_type, 540a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const base::FilePath& local_file_path, 541c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const UploadRangeCallback& callback, 542c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const ProgressCallback& progress_callback) { 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 5442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 547868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new ResumeUploadRequest(sender_.get(), 548eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback, 549eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch progress_callback, 550eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch upload_url, 551eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch start_position, 552eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch end_position, 553eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch content_length, 554eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch content_type, 555eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch local_file_path)); 5562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::GetUploadStatus( 5592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& upload_url, 5602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int64 content_length, 5612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const UploadRangeCallback& callback) { 5622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 5632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 566868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) new GetUploadStatusRequest(sender_.get(), 567eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback, 568eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch upload_url, 569eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch content_length)); 5702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)CancelCallback GDataWapiService::AuthorizeApp( 5737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const std::string& resource_id, 5747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const std::string& app_id, 5757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const AuthorizeAppCallback& callback) { 5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 5772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(!callback.is_null()); 5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return sender_->StartRequestWithRetry( 580eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch new AuthorizeAppRequest(sender_.get(), 581eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch url_generator_, 582eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch callback, 583eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch resource_id, 584eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch app_id)); 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 58758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)CancelCallback GDataWapiService::GetResourceListInDirectoryByWapi( 58858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const std::string& directory_resource_id, 58958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const google_apis::GetResourceListCallback& callback) { 59058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return GetResourceListInDirectory(directory_resource_id, callback); 59158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 59258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 59358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)CancelCallback GDataWapiService::GetRemainingResourceList( 59458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const GURL& next_link, 59558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const google_apis::GetResourceListCallback& callback) { 59658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 59758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(!next_link.is_empty()); 59858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(!callback.is_null()); 59958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 60058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return sender_->StartRequestWithRetry( 60158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) new GetResourceListRequest(sender_.get(), 60258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) url_generator_, 60358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) next_link, 60458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 0, // start changestamp 60558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) std::string(), // empty search query 60658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) std::string(), // no directory resource id 60758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) callback)); 60858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 60958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool GDataWapiService::HasAccessToken() const { 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 613868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return sender_->auth_service()->HasAccessToken(); 6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid GDataWapiService::RequestAccessToken(const AuthStatusCallback& callback) { 6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 6187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch DCHECK(!callback.is_null()); 6197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 6207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const std::string access_token = sender_->auth_service()->access_token(); 6217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (!access_token.empty()) { 6227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch callback.Run(google_apis::HTTP_NOT_MODIFIED, access_token); 6237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return; 6247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Retrieve the new auth token. 6277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch sender_->auth_service()->StartAuthentication(callback); 6287dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} 6297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 6307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochbool GDataWapiService::HasRefreshToken() const { 6317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 632868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return sender_->auth_service()->HasRefreshToken(); 6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void GDataWapiService::ClearAccessToken() { 6362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 6377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch sender_->auth_service()->ClearAccessToken(); 6382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void GDataWapiService::ClearRefreshToken() { 6412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 6427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch sender_->auth_service()->ClearRefreshToken(); 6432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void GDataWapiService::OnOAuth2RefreshTokenChanged() { 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 647868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (CanSendRequest()) { 6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FOR_EACH_OBSERVER( 649868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) DriveServiceObserver, observers_, OnReadyToSendRequests()); 6502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else if (!HasRefreshToken()) { 6512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FOR_EACH_OBSERVER( 6522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DriveServiceObserver, observers_, OnRefreshTokenInvalid()); 6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 656eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} // namespace drive 657