Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Side by Side Diff: chrome/browser/google_apis/drive_api_service.cc

Issue 14013005: Move EscapeQueryStringValue to drive_api_util. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/google_apis/drive_api_service.h" 5 #include "chrome/browser/google_apis/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/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/task_runner_util.h" 14 #include "base/task_runner_util.h"
15 #include "base/threading/sequenced_worker_pool.h" 15 #include "base/threading/sequenced_worker_pool.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/google_apis/auth_service.h" 17 #include "chrome/browser/google_apis/auth_service.h"
18 #include "chrome/browser/google_apis/drive_api_operations.h" 18 #include "chrome/browser/google_apis/drive_api_operations.h"
19 #include "chrome/browser/google_apis/drive_api_parser.h" 19 #include "chrome/browser/google_apis/drive_api_parser.h"
20 #include "chrome/browser/google_apis/drive_api_util.h"
20 #include "chrome/browser/google_apis/gdata_wapi_operations.h" 21 #include "chrome/browser/google_apis/gdata_wapi_operations.h"
21 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 22 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
22 #include "chrome/browser/google_apis/operation_runner.h" 23 #include "chrome/browser/google_apis/operation_runner.h"
23 #include "chrome/browser/google_apis/time_util.h" 24 #include "chrome/browser/google_apis/time_util.h"
24 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
25 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
26 27
27 using content::BrowserThread; 28 using content::BrowserThread;
28 29
29 namespace google_apis { 30 namespace google_apis {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 callback.Run(UploadRangeResponse(GDATA_PARSE_ERROR, 195 callback.Run(UploadRangeResponse(GDATA_PARSE_ERROR,
195 response.start_position_received, 196 response.start_position_received,
196 response.end_position_received), 197 response.end_position_received),
197 scoped_ptr<ResourceEntry>()); 198 scoped_ptr<ResourceEntry>());
198 return; 199 return;
199 } 200 }
200 201
201 callback.Run(response, entry.Pass()); 202 callback.Run(response, entry.Pass());
202 } 203 }
203 204
204 // It is necessary to escape ' to \' in the query's string value.
205 // See also: https://developers.google.com/drive/search-parameters
206 std::string EscapeQueryStringValue(const std::string& str) {
207 std::string result;
208 ReplaceChars(str, "'", "\\'", &result);
209 return result;
210 }
211
212 // The resource ID for the root directory for Drive API is defined in the spec: 205 // The resource ID for the root directory for Drive API is defined in the spec:
213 // https://developers.google.com/drive/folder 206 // https://developers.google.com/drive/folder
214 const char kDriveApiRootDirectoryResourceId[] = "root"; 207 const char kDriveApiRootDirectoryResourceId[] = "root";
215 208
216 } // namespace 209 } // namespace
217 210
218 DriveAPIService::DriveAPIService( 211 DriveAPIService::DriveAPIService(
219 net::URLRequestContextGetter* url_request_context_getter, 212 net::URLRequestContextGetter* url_request_context_getter,
220 const GURL& base_url, 213 const GURL& base_url,
221 const GURL& wapi_base_url, 214 const GURL& wapi_base_url,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 // code up by moving the resposibility to include "parents" in the query 313 // code up by moving the resposibility to include "parents" in the query
321 // to client side. 314 // to client side.
322 // We aren't interested in files in trash in this context, neither. 315 // We aren't interested in files in trash in this context, neither.
323 runner_->StartOperationWithRetry( 316 runner_->StartOperationWithRetry(
324 new GetFilelistOperation( 317 new GetFilelistOperation(
325 operation_registry(), 318 operation_registry(),
326 url_request_context_getter_, 319 url_request_context_getter_,
327 url_generator_, 320 url_generator_,
328 base::StringPrintf( 321 base::StringPrintf(
329 "'%s' in parents and trashed = false", 322 "'%s' in parents and trashed = false",
330 EscapeQueryStringValue(directory_resource_id).c_str()), 323 drive::util::EscapeQueryStringValue(
324 directory_resource_id).c_str()),
331 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback))); 325 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
332 } 326 }
333 327
334 void DriveAPIService::Search(const std::string& search_query, 328 void DriveAPIService::Search(const std::string& search_query,
335 const GetResourceListCallback& callback) { 329 const GetResourceListCallback& callback) {
336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
337 DCHECK(!search_query.empty()); 331 DCHECK(!search_query.empty());
338 DCHECK(!callback.is_null()); 332 DCHECK(!callback.is_null());
339 333
340 runner_->StartOperationWithRetry( 334 runner_->StartOperationWithRetry(
(...skipping 15 matching lines...) Expand all
356 DCHECK(!callback.is_null()); 350 DCHECK(!callback.is_null());
357 351
358 runner_->StartOperationWithRetry( 352 runner_->StartOperationWithRetry(
359 new GetFilelistOperation( 353 new GetFilelistOperation(
360 operation_registry(), 354 operation_registry(),
361 url_request_context_getter_, 355 url_request_context_getter_,
362 url_generator_, 356 url_generator_,
363 base::StringPrintf( 357 base::StringPrintf(
364 "%s and '%s' in parents and trashed = false", 358 "%s and '%s' in parents and trashed = false",
365 search_query.c_str(), 359 search_query.c_str(),
366 EscapeQueryStringValue(directory_resource_id).c_str()), 360 drive::util::EscapeQueryStringValue(
361 directory_resource_id).c_str()),
367 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback))); 362 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
368 } 363 }
369 364
370 void DriveAPIService::GetChangeList(int64 start_changestamp, 365 void DriveAPIService::GetChangeList(int64 start_changestamp,
371 const GetResourceListCallback& callback) { 366 const GetResourceListCallback& callback) {
372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
373 DCHECK(!callback.is_null()); 368 DCHECK(!callback.is_null());
374 369
375 runner_->StartOperationWithRetry( 370 runner_->StartOperationWithRetry(
376 new GetChangelistOperation( 371 new GetChangelistOperation(
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 } 713 }
719 714
720 void DriveAPIService::OnProgressUpdate( 715 void DriveAPIService::OnProgressUpdate(
721 const OperationProgressStatusList& list) { 716 const OperationProgressStatusList& list) {
722 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 717 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
723 FOR_EACH_OBSERVER( 718 FOR_EACH_OBSERVER(
724 DriveServiceObserver, observers_, OnProgressUpdate(list)); 719 DriveServiceObserver, observers_, OnProgressUpdate(list));
725 } 720 }
726 721
727 } // namespace google_apis 722 } // namespace google_apis
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/google_apis/drive_api_util.h » ('j') | chrome/browser/google_apis/drive_api_util.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698