OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_USER_STYLE_SHEET_WATCHER_H_ | |
6 #define CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_H_ | |
7 | |
8 #include "base/callback_list.h" | |
9 #include "base/files/file_path.h" | |
10 #include "base/files/file_path_watcher.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/sequenced_task_runner_helpers.h" | |
14 #include "components/browser_context_keyed_service/refcounted_browser_context_ke
yed_service.h" | |
15 #include "content/public/browser/notification_observer.h" | |
16 #include "content/public/browser/notification_registrar.h" | |
17 #include "url/gurl.h" | |
18 | |
19 class Profile; | |
20 class UserStyleSheetLoader; | |
21 | |
22 // Watches the user style sheet file and triggers reloads on the file thread | |
23 // whenever the file changes. | |
24 class UserStyleSheetWatcher | |
25 : public content::NotificationObserver, | |
26 public RefcountedBrowserContextKeyedService { | |
27 public: | |
28 UserStyleSheetWatcher(Profile* profile, const base::FilePath& profile_path); | |
29 | |
30 void Init(); | |
31 | |
32 GURL user_style_sheet() const; | |
33 | |
34 // Register a callback to be called whenever the stylesheet gets updated. | |
35 scoped_ptr<base::CallbackList<void(void)>::Subscription> | |
36 RegisterOnStyleSheetUpdatedCallback(const base::Closure& callback); | |
37 | |
38 // content::NotificationObserver interface | |
39 virtual void Observe(int type, | |
40 const content::NotificationSource& source, | |
41 const content::NotificationDetails& details) OVERRIDE; | |
42 | |
43 // RefCountedProfileKeyedBase method override. | |
44 virtual void ShutdownOnUIThread() OVERRIDE; | |
45 | |
46 private: | |
47 friend class base::DeleteHelper<UserStyleSheetWatcher>; | |
48 | |
49 virtual ~UserStyleSheetWatcher(); | |
50 | |
51 // The profile owning us. | |
52 Profile* profile_; | |
53 | |
54 // The directory containing User StyleSheets/Custom.css. | |
55 base::FilePath profile_path_; | |
56 | |
57 // The loader object. | |
58 scoped_refptr<UserStyleSheetLoader> loader_; | |
59 | |
60 // Watches for changes to the css file so we can reload the style sheet. | |
61 scoped_ptr<base::FilePathWatcher> file_watcher_; | |
62 | |
63 content::NotificationRegistrar registrar_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(UserStyleSheetWatcher); | |
66 }; | |
67 | |
68 #endif // CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_H_ | |
OLD | NEW |