OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_COMMON_IMPORTANT_FILE_WRITER_H_ | 5 #ifndef CHROME_COMMON_IMPORTANT_FILE_WRITER_H_ |
6 #define CHROME_COMMON_IMPORTANT_FILE_WRITER_H_ | 6 #define CHROME_COMMON_IMPORTANT_FILE_WRITER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
14 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "base/timer.h" | 16 #include "base/timer.h" |
| 17 #include "content/common/notification_source.h" |
17 | 18 |
18 namespace base { | 19 namespace base { |
19 class MessageLoopProxy; | 20 class MessageLoopProxy; |
20 class Thread; | 21 class Thread; |
21 } | 22 } |
22 | 23 |
23 // Helper to ensure that a file won't be corrupted by the write (for example on | 24 // Helper to ensure that a file won't be corrupted by the write (for example on |
24 // application crash). Consider a naive way to save an important file F: | 25 // application crash). Consider a naive way to save an important file F: |
25 // | 26 // |
26 // 1. Open F for writing, truncating it. | 27 // 1. Open F for writing, truncating it. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 void DoScheduledWrite(); | 85 void DoScheduledWrite(); |
85 | 86 |
86 base::TimeDelta commit_interval() const { | 87 base::TimeDelta commit_interval() const { |
87 return commit_interval_; | 88 return commit_interval_; |
88 } | 89 } |
89 | 90 |
90 void set_commit_interval(const base::TimeDelta& interval) { | 91 void set_commit_interval(const base::TimeDelta& interval) { |
91 commit_interval_ = interval; | 92 commit_interval_ = interval; |
92 } | 93 } |
93 | 94 |
| 95 void set_notification_source(NotificationSource source) { source_ = source; } |
| 96 |
94 private: | 97 private: |
95 // Path being written to. | 98 // Path being written to. |
96 const FilePath path_; | 99 const FilePath path_; |
97 | 100 |
98 // MessageLoopProxy for the thread on which file I/O can be done. | 101 // MessageLoopProxy for the thread on which file I/O can be done. |
99 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy_; | 102 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy_; |
100 | 103 |
101 // Timer used to schedule commit after ScheduleWrite. | 104 // Timer used to schedule commit after ScheduleWrite. |
102 base::OneShotTimer<ImportantFileWriter> timer_; | 105 base::OneShotTimer<ImportantFileWriter> timer_; |
103 | 106 |
104 // Serializer which will provide the data to be saved. | 107 // Serializer which will provide the data to be saved. |
105 DataSerializer* serializer_; | 108 DataSerializer* serializer_; |
106 | 109 |
107 // Time delta after which scheduled data will be written to disk. | 110 // Time delta after which scheduled data will be written to disk. |
108 base::TimeDelta commit_interval_; | 111 base::TimeDelta commit_interval_; |
109 | 112 |
| 113 // Used as source for PREF_COMMITTED notification. |
| 114 NotificationSource source_; |
| 115 |
110 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter); | 116 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter); |
111 }; | 117 }; |
112 | 118 |
113 #endif // CHROME_COMMON_IMPORTANT_FILE_WRITER_H_ | 119 #endif // CHROME_COMMON_IMPORTANT_FILE_WRITER_H_ |
OLD | NEW |