1a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// found in the LICENSE file.
4a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
5a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_SEARCH_OPERATION_H_
6a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_SEARCH_OPERATION_H_
7a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
8a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/basictypes.h"
9a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/memory/ref_counted.h"
10a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
11a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/memory/weak_ptr.h"
12a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "chrome/browser/chromeos/drive/file_errors.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/chromeos/drive/file_system_interface.h"
14a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "google_apis/drive/gdata_errorcode.h"
15a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace base {
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class SequencedTaskRunner;
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}  // namespace base
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
20a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace google_apis {
2146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)class FileList;
22a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}  // namespace google_apis
23a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
24a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace drive {
25a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
26a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class JobScheduler;
27a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
28a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace internal {
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class LoaderController;
30a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class ResourceMetadata;
31a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}  // namespace internal
32a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
33a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace file_system {
34a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
35a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// This class encapsulates the drive Search function. It is responsible for
36a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// sending the request to the drive API.
37a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class SearchOperation {
38a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) public:
3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SearchOperation(base::SequencedTaskRunner* blocking_task_runner,
4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                  JobScheduler* scheduler,
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  internal::ResourceMetadata* metadata,
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  internal::LoaderController* loader_controller);
43a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  ~SearchOperation();
44a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Performs server side content search operation for |search_query|.  If
4658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // |next_link| is set, this is the search result url that will be fetched.
47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Upon completion, |callback| will be called with the result.  This is
48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // implementation of FileSystemInterface::Search() method.
49a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  //
50a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // |callback| must not be null.
51a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  void Search(const std::string& search_query,
5258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)              const GURL& next_link,
53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)              const SearchCallback& callback);
54a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
55a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) private:
5646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Part of Search(), called after the FileList is fetched from the server.
5746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  void SearchAfterGetFileList(
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const SearchCallback& callback,
59a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      google_apis::GDataErrorCode gdata_error,
6046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      scoped_ptr<google_apis::FileList> file_list);
61a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
62424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Part of Search(), called after |result| is filled on the blocking pool.
63424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  void SearchAfterResolveSearchResult(
64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const SearchCallback& callback,
6558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      const GURL& next_link,
66a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      scoped_ptr<std::vector<SearchResultInfo> > result,
67a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      FileError error);
68a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
69a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  JobScheduler* scheduler_;
7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  internal::ResourceMetadata* metadata_;
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  internal::LoaderController* loader_controller_;
73a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
74a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Note: This should remain the last member so it'll be destroyed and
75a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // invalidate the weak pointers before any other members are destroyed.
76a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  base::WeakPtrFactory<SearchOperation> weak_ptr_factory_;
77a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SearchOperation);
78a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)};
79a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
80a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}  // namespace file_system
81a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}  // namespace drive
82a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
83a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#endif  // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_SEARCH_OPERATION_H_
84