| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/user_style_sheet_watcher.h" | 5 #include "chrome/browser/user_style_sheet_watcher.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 // '----------------------' | 40 // '----------------------' |
| 41 // | 41 // |
| 42 // FilePathWatcher's reference to UserStyleSheetLoader is used for delivering | 42 // FilePathWatcher's reference to UserStyleSheetLoader is used for delivering |
| 43 // the change notifications. Since they happen asynchronously, | 43 // the change notifications. Since they happen asynchronously, |
| 44 // UserStyleSheetWatcher and its FilePathWatcher may be destroyed while a | 44 // UserStyleSheetWatcher and its FilePathWatcher may be destroyed while a |
| 45 // callback to UserStyleSheetLoader is in progress, in which case the | 45 // callback to UserStyleSheetLoader is in progress, in which case the |
| 46 // UserStyleSheetLoader object outlives the watchers. | 46 // UserStyleSheetLoader object outlives the watchers. |
| 47 class UserStyleSheetLoader : public FilePathWatcher::Delegate { | 47 class UserStyleSheetLoader : public FilePathWatcher::Delegate { |
| 48 public: | 48 public: |
| 49 UserStyleSheetLoader(); | 49 UserStyleSheetLoader(); |
| 50 virtual ~UserStyleSheetLoader() {} | |
| 51 | 50 |
| 52 GURL user_style_sheet() const { | 51 GURL user_style_sheet() const { |
| 53 return user_style_sheet_; | 52 return user_style_sheet_; |
| 54 } | 53 } |
| 55 | 54 |
| 56 // Load the user style sheet on the file thread and convert it to a | 55 // Load the user style sheet on the file thread and convert it to a |
| 57 // base64 URL. Posts the base64 URL back to the UI thread. | 56 // base64 URL. Posts the base64 URL back to the UI thread. |
| 58 void LoadStyleSheet(const FilePath& style_sheet_file); | 57 void LoadStyleSheet(const FilePath& style_sheet_file); |
| 59 | 58 |
| 60 // Send out a notification if the stylesheet has already been loaded. | 59 // Send out a notification if the stylesheet has already been loaded. |
| 61 void NotifyLoaded(); | 60 void NotifyLoaded(); |
| 62 | 61 |
| 63 // FilePathWatcher::Delegate interface | 62 // FilePathWatcher::Delegate interface |
| 64 virtual void OnFilePathChanged(const FilePath& path); | 63 virtual void OnFilePathChanged(const FilePath& path); |
| 65 | 64 |
| 66 private: | 65 private: |
| 66 virtual ~UserStyleSheetLoader() {} |
| 67 |
| 67 // Called on the UI thread after the stylesheet has loaded. | 68 // Called on the UI thread after the stylesheet has loaded. |
| 68 void SetStyleSheet(const GURL& url); | 69 void SetStyleSheet(const GURL& url); |
| 69 | 70 |
| 70 // The user style sheet as a base64 data:// URL. | 71 // The user style sheet as a base64 data:// URL. |
| 71 GURL user_style_sheet_; | 72 GURL user_style_sheet_; |
| 72 | 73 |
| 73 // Whether the stylesheet has been loaded. | 74 // Whether the stylesheet has been loaded. |
| 74 bool has_loaded_; | 75 bool has_loaded_; |
| 75 | 76 |
| 76 DISALLOW_COPY_AND_ASSIGN(UserStyleSheetLoader); | 77 DISALLOW_COPY_AND_ASSIGN(UserStyleSheetLoader); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 if (profile_->IsSameProfile(Profile::FromBrowserContext( | 181 if (profile_->IsSameProfile(Profile::FromBrowserContext( |
| 181 content::Source<WebContents>(source)->GetBrowserContext()))) { | 182 content::Source<WebContents>(source)->GetBrowserContext()))) { |
| 182 loader_->NotifyLoaded(); | 183 loader_->NotifyLoaded(); |
| 183 registrar_.RemoveAll(); | 184 registrar_.RemoveAll(); |
| 184 } | 185 } |
| 185 } | 186 } |
| 186 | 187 |
| 187 void UserStyleSheetWatcher::ShutdownOnUIThread() { | 188 void UserStyleSheetWatcher::ShutdownOnUIThread() { |
| 188 registrar_.RemoveAll(); | 189 registrar_.RemoveAll(); |
| 189 } | 190 } |
| OLD | NEW |