• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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 #pragma once
8 
9 #include "base/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 "content/browser/browser_thread.h"
14 #include "content/common/notification_observer.h"
15 #include "content/common/notification_registrar.h"
16 #include "googleurl/src/gurl.h"
17 
18 class UserStyleSheetLoader;
19 
20 // Watches the user style sheet file and triggers reloads on the file thread
21 // whenever the file changes.
22 class UserStyleSheetWatcher
23     : public base::RefCountedThreadSafe<UserStyleSheetWatcher,
24                                         BrowserThread::DeleteOnUIThread>,
25       public NotificationObserver {
26  public:
27   explicit UserStyleSheetWatcher(const FilePath& profile_path);
28 
29   void Init();
30 
31   GURL user_style_sheet() const;
32 
33   // NotificationObserver interface
34   virtual void Observe(NotificationType type,
35                        const NotificationSource& source,
36                        const NotificationDetails& details);
37 
38  private:
39   friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
40   friend class DeleteTask<UserStyleSheetWatcher>;
41 
42   virtual ~UserStyleSheetWatcher();
43 
44   // The directory containing User StyleSheets/Custom.css.
45   FilePath profile_path_;
46 
47   // The loader object.
48   scoped_refptr<UserStyleSheetLoader> loader_;
49 
50   // Watches for changes to the css file so we can reload the style sheet.
51   scoped_ptr<base::files::FilePathWatcher> file_watcher_;
52 
53   NotificationRegistrar registrar_;
54 
55   DISALLOW_COPY_AND_ASSIGN(UserStyleSheetWatcher);
56 };
57 
58 #endif  // CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_H_
59