1 // Copyright 2017 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_FILEAPI_RECENT_DRIVE_SOURCE_H_
6 #define CHROME_BROWSER_CHROMEOS_FILEAPI_RECENT_DRIVE_SOURCE_H_
7 
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 #include "base/files/file.h"
13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/optional.h"
16 #include "base/time/time.h"
17 #include "chrome/browser/chromeos/fileapi/recent_source.h"
18 #include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
19 #include "components/drive/file_errors.h"
20 #include "mojo/public/cpp/bindings/remote.h"
21 
22 class Profile;
23 
24 namespace chromeos {
25 
26 class RecentFile;
27 
28 // RecentSource implementation for Drive files.
29 //
30 // All member functions must be called on the UI thread.
31 //
32 // TODO(nya): Write unit tests.
33 class RecentDriveSource : public RecentSource {
34  public:
35   explicit RecentDriveSource(Profile* profile);
36   ~RecentDriveSource() override;
37 
38   // RecentSource overrides:
39   void GetRecentFiles(Params params) override;
40 
41  private:
42   static const char kLoadHistogramName[];
43 
44   void OnComplete();
45 
46   void GotSearchResults(
47       drive::FileError error,
48       base::Optional<std::vector<drivefs::mojom::QueryItemPtr>> results);
49 
50   Profile* const profile_;
51 
52   // Set at the beginning of GetRecentFiles().
53   base::Optional<Params> params_;
54 
55   base::TimeTicks build_start_time_;
56 
57   std::vector<RecentFile> files_;
58 
59   mojo::Remote<drivefs::mojom::SearchQuery> search_query_;
60 
61   base::WeakPtrFactory<RecentDriveSource> weak_ptr_factory_{this};
62 
63   DISALLOW_COPY_AND_ASSIGN(RecentDriveSource);
64 };
65 
66 }  // namespace chromeos
67 
68 #endif  // CHROME_BROWSER_CHROMEOS_FILEAPI_RECENT_DRIVE_SOURCE_H_
69