search_operation.h revision 868fa2fe829687343ffae624259930155e16dbd8
1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_SEARCH_OPERATION_H_ 6#define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_SEARCH_OPERATION_H_ 7 8#include "base/basictypes.h" 9#include "base/memory/ref_counted.h" 10#include "base/memory/scoped_ptr.h" 11#include "base/memory/weak_ptr.h" 12#include "chrome/browser/chromeos/drive/file_errors.h" 13#include "chrome/browser/chromeos/drive/file_system_interface.h" 14#include "chrome/browser/google_apis/gdata_errorcode.h" 15 16class GURL; 17 18namespace base { 19class SequencedTaskRunner; 20} // namespace base 21 22namespace google_apis { 23class ResourceEntry; 24class ResourceList; 25} // namespace google_apis 26 27namespace drive { 28 29class JobScheduler; 30 31namespace internal { 32class ResourceMetadata; 33} // namespace internal 34 35namespace file_system { 36 37// This class encapsulates the drive Search function. It is responsible for 38// sending the request to the drive API. 39class SearchOperation { 40 public: 41 SearchOperation(base::SequencedTaskRunner* blocking_task_runner, 42 JobScheduler* scheduler, 43 internal::ResourceMetadata* metadata); 44 ~SearchOperation(); 45 46 // Performs server side content search operation for |search_query|. If 47 // |next_url| is set, this is the search result url that will be fetched. 48 // Upon completion, |callback| will be called with the result. This is 49 // implementation of FileSystemInterface::Search() method. 50 // 51 // |callback| must not be null. 52 void Search(const std::string& search_query, 53 const GURL& next_url, 54 const SearchCallback& callback); 55 56 private: 57 // Part of Search(). This is called after the ResourceList is fetched from 58 // the server. 59 void SearchAfterGetResourceList( 60 const SearchCallback& callback, 61 google_apis::GDataErrorCode gdata_error, 62 scoped_ptr<google_apis::ResourceList> resource_list); 63 64 // Part of Search(). This is called after the RefreshEntryOnBlockingPool 65 // is completed. 66 void SearchAfterRefreshEntry( 67 const SearchCallback& callback, 68 const GURL& next_url, 69 scoped_ptr<std::vector<SearchResultInfo> > result, 70 FileError error); 71 72 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 73 JobScheduler* scheduler_; 74 internal::ResourceMetadata* metadata_; 75 76 // Note: This should remain the last member so it'll be destroyed and 77 // invalidate the weak pointers before any other members are destroyed. 78 base::WeakPtrFactory<SearchOperation> weak_ptr_factory_; 79 DISALLOW_COPY_AND_ASSIGN(SearchOperation); 80}; 81 82} // namespace file_system 83} // namespace drive 84 85#endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_SEARCH_OPERATION_H_ 86