search_operation.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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 "google_apis/drive/gdata_errorcode.h" 15 16namespace base { 17class SequencedTaskRunner; 18} // namespace base 19 20namespace google_apis { 21class ResourceEntry; 22class ResourceList; 23} // namespace google_apis 24 25namespace drive { 26 27class JobScheduler; 28 29namespace internal { 30class ResourceMetadata; 31} // namespace internal 32 33namespace file_system { 34 35// This class encapsulates the drive Search function. It is responsible for 36// sending the request to the drive API. 37class SearchOperation { 38 public: 39 SearchOperation(base::SequencedTaskRunner* blocking_task_runner, 40 JobScheduler* scheduler, 41 internal::ResourceMetadata* metadata); 42 ~SearchOperation(); 43 44 // Performs server side content search operation for |search_query|. If 45 // |next_link| is set, this is the search result url that will be fetched. 46 // Upon completion, |callback| will be called with the result. This is 47 // implementation of FileSystemInterface::Search() method. 48 // 49 // |callback| must not be null. 50 void Search(const std::string& search_query, 51 const GURL& next_link, 52 const SearchCallback& callback); 53 54 private: 55 // Part of Search(), called after the ResourceList is fetched from the server. 56 void SearchAfterGetResourceList( 57 const SearchCallback& callback, 58 google_apis::GDataErrorCode gdata_error, 59 scoped_ptr<google_apis::ResourceList> resource_list); 60 61 // Part of Search(), called after |result| is filled on the blocking pool. 62 void SearchAfterResolveSearchResult( 63 const SearchCallback& callback, 64 const GURL& next_link, 65 scoped_ptr<std::vector<SearchResultInfo> > result, 66 FileError error); 67 68 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 69 JobScheduler* scheduler_; 70 internal::ResourceMetadata* metadata_; 71 72 // Note: This should remain the last member so it'll be destroyed and 73 // invalidate the weak pointers before any other members are destroyed. 74 base::WeakPtrFactory<SearchOperation> weak_ptr_factory_; 75 DISALLOW_COPY_AND_ASSIGN(SearchOperation); 76}; 77 78} // namespace file_system 79} // namespace drive 80 81#endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_SEARCH_OPERATION_H_ 82