OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_BROWSER_USER_STYLE_SHEET_WATCHER_H_ | 5 #ifndef CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_H_ |
6 #define CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_H_ | 6 #define CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_H_ |
7 | 7 |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
11 #include "chrome/browser/chrome_thread.h" | 11 #include "chrome/browser/chrome_thread.h" |
| 12 #include "chrome/browser/file_watcher.h" |
12 #include "chrome/common/notification_observer.h" | 13 #include "chrome/common/notification_observer.h" |
13 #include "chrome/common/notification_registrar.h" | 14 #include "chrome/common/notification_registrar.h" |
14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
15 | 16 |
16 // This loads the user style sheet on the file thread and sends a notification | 17 // This loads the user style sheet on the file thread and sends a notification |
17 // when the style sheet is loaded. | 18 // when the style sheet is loaded. |
18 // TODO(tony): Watch for file changes and send a notification of the update. | |
19 class UserStyleSheetWatcher | 19 class UserStyleSheetWatcher |
20 : public base::RefCountedThreadSafe<UserStyleSheetWatcher, | 20 : public base::RefCountedThreadSafe<UserStyleSheetWatcher, |
21 ChromeThread::DeleteOnUIThread>, | 21 ChromeThread::DeleteOnUIThread>, |
22 public NotificationObserver { | 22 public NotificationObserver, |
| 23 public FileWatcher::Delegate { |
23 public: | 24 public: |
24 explicit UserStyleSheetWatcher(const FilePath& profile_path); | 25 explicit UserStyleSheetWatcher(const FilePath& profile_path); |
25 virtual ~UserStyleSheetWatcher() {} | 26 virtual ~UserStyleSheetWatcher() {} |
26 | 27 |
27 void Init(); | 28 void Init(); |
28 | 29 |
29 GURL user_style_sheet() const { | 30 GURL user_style_sheet() const { |
30 return user_style_sheet_; | 31 return user_style_sheet_; |
31 } | 32 } |
32 | 33 |
33 // NotificationObserver interface | 34 // NotificationObserver interface |
34 virtual void Observe(NotificationType type, | 35 virtual void Observe(NotificationType type, |
35 const NotificationSource& source, | 36 const NotificationSource& source, |
36 const NotificationDetails& details); | 37 const NotificationDetails& details); |
37 | 38 |
| 39 // FileWatcher::Delegate interface |
| 40 virtual void OnFileChanged(const FilePath& path); |
| 41 |
38 private: | 42 private: |
39 // Load the user style sheet on the file thread and convert it to a | 43 // Load the user style sheet on the file thread and convert it to a |
40 // base64 URL. Posts the base64 URL back to the UI thread. | 44 // base64 URL. Posts the base64 URL back to the UI thread. |
41 void LoadStyleSheet(const FilePath& profile_path); | 45 void LoadStyleSheet(const FilePath& profile_path); |
42 | 46 |
43 void SetStyleSheet(const GURL& url); | 47 void SetStyleSheet(const GURL& url); |
44 | 48 |
45 // The directory containing the User StyleSheet. | 49 // The directory containing User StyleSheets/Custom.css. |
46 FilePath profile_path_; | 50 FilePath profile_path_; |
47 | 51 |
48 // The user style sheet as a base64 data:// URL. | 52 // The user style sheet as a base64 data:// URL. |
49 GURL user_style_sheet_; | 53 GURL user_style_sheet_; |
50 | 54 |
| 55 // Watches for changes to the css file so we can reload the style sheet. |
| 56 scoped_ptr<FileWatcher> file_watcher_; |
| 57 |
51 NotificationRegistrar registrar_; | 58 NotificationRegistrar registrar_; |
52 bool has_loaded_; | 59 bool has_loaded_; |
53 | 60 |
54 DISALLOW_COPY_AND_ASSIGN(UserStyleSheetWatcher); | 61 DISALLOW_COPY_AND_ASSIGN(UserStyleSheetWatcher); |
55 }; | 62 }; |
56 | 63 |
57 #endif // CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_H_ | 64 #endif // CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_H_ |
OLD | NEW |