OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 COMPONENTS_UPDATE_CLIENT_PERSISTED_DATA_H_ |
| 6 #define COMPONENTS_UPDATE_CLIENT_PERSISTED_DATA_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/files/file_path.h" |
| 12 #include "base/files/important_file_writer.h" |
| 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/threading/thread_checker.h" |
| 17 #include "base/values.h" |
| 18 |
| 19 namespace base { |
| 20 |
| 21 class SequencedTaskRunner; |
| 22 class SingleThreadTaskRunner; |
| 23 |
| 24 } // namespace base |
| 25 |
| 26 namespace update_client { |
| 27 |
| 28 // A PersistedData is a storer and provider of any per-component metadata |
| 29 // that outlives the browser process and isn't exposed outside of update_client. |
| 30 // |
| 31 // It implements an in-memory data structure that is initialized from disk upon |
| 32 // startup. Writes to the data structure are written to the disk. |
| 33 // |
| 34 // The public methods of this class should be called only on the thread that |
| 35 // initializes it. |
| 36 class PersistedData : public base::RefCountedThreadSafe<PersistedData> { |
| 37 public: |
| 38 // Constructs a provider that uses a file at the specified |path|. The |
| 39 // |task_runner| will be used to serialize the data. |
| 40 PersistedData( |
| 41 const base::FilePath& path, |
| 42 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
| 43 |
| 44 // Returns the DateLastRollCall of the specified |id|. -2 indicates that there |
| 45 // is no record of the app. |
| 46 int DateLastRollCall(const std::string& id) const; |
| 47 |
| 48 // Records the DateLastRollCall for the specified |ids|. |datenum| must be a |
| 49 // non-negative integer: calls with a negative |datenum| are simply ignored. |
| 50 // Calls to SetDateLastRollCall that occur prior to the persisted data store |
| 51 // has been fully initialized are ignored. |
| 52 void SetDateLastRollCall(const std::vector<std::string>& ids, int datenum); |
| 53 |
| 54 private: |
| 55 friend class base::RefCountedThreadSafe<PersistedData>; |
| 56 |
| 57 ~PersistedData(); |
| 58 |
| 59 void Initialize( |
| 60 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner); |
| 61 void LoadFromFile(); |
| 62 void Ready(); |
| 63 |
| 64 base::ThreadChecker thread_checker_; |
| 65 |
| 66 const base::FilePath path_; |
| 67 base::ImportantFileWriter file_writer_; |
| 68 scoped_ptr<base::DictionaryValue> metadata_; |
| 69 bool ready_; |
| 70 const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(PersistedData); |
| 73 }; |
| 74 |
| 75 } // namespace update_client |
| 76 |
| 77 #endif // COMPONENTS_UPDATE_CLIENT_PERSISTED_DATA_H_ |
OLD | NEW |