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