Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/browser/user_style_sheet_watcher.cc

Issue 6793020: Move FilePathWatcher to base/files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move OWNERS file and rebase to pick up latest changes Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/file_util.h" 8 #include "base/file_util.h"
9 #include "content/common/notification_service.h" 9 #include "content/common/notification_service.h"
10 #include "content/common/notification_type.h" 10 #include "content/common/notification_type.h"
(...skipping 18 matching lines...) Expand all
29 // V | 29 // V |
30 // .----------------------. | 30 // .----------------------. |
31 // | UserStyleSheetLoader |<--------------------' 31 // | UserStyleSheetLoader |<--------------------'
32 // '----------------------' 32 // '----------------------'
33 // 33 //
34 // FilePathWatcher's reference to UserStyleSheetLoader is used for delivering 34 // FilePathWatcher's reference to UserStyleSheetLoader is used for delivering
35 // the change notifications. Since they happen asynchronously, 35 // the change notifications. Since they happen asynchronously,
36 // UserStyleSheetWatcher and its FilePathWatcher may be destroyed while a 36 // UserStyleSheetWatcher and its FilePathWatcher may be destroyed while a
37 // callback to UserStyleSheetLoader is in progress, in which case the 37 // callback to UserStyleSheetLoader is in progress, in which case the
38 // UserStyleSheetLoader object outlives the watchers. 38 // UserStyleSheetLoader object outlives the watchers.
39 class UserStyleSheetLoader : public FilePathWatcher::Delegate { 39 class UserStyleSheetLoader : public base::files::FilePathWatcher::Delegate {
40 public: 40 public:
41 UserStyleSheetLoader(); 41 UserStyleSheetLoader();
42 virtual ~UserStyleSheetLoader() {} 42 virtual ~UserStyleSheetLoader() {}
43 43
44 GURL user_style_sheet() const { 44 GURL user_style_sheet() const {
45 return user_style_sheet_; 45 return user_style_sheet_;
46 } 46 }
47 47
48 // Load the user style sheet on the file thread and convert it to a 48 // Load the user style sheet on the file thread and convert it to a
49 // base64 URL. Posts the base64 URL back to the UI thread. 49 // base64 URL. Posts the base64 URL back to the UI thread.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 138
139 void UserStyleSheetWatcher::Init() { 139 void UserStyleSheetWatcher::Init() {
140 // Make sure we run on the file thread. 140 // Make sure we run on the file thread.
141 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { 141 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) {
142 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 142 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
143 NewRunnableMethod(this, &UserStyleSheetWatcher::Init)); 143 NewRunnableMethod(this, &UserStyleSheetWatcher::Init));
144 return; 144 return;
145 } 145 }
146 146
147 if (!file_watcher_.get()) { 147 if (!file_watcher_.get()) {
148 file_watcher_.reset(new FilePathWatcher); 148 file_watcher_.reset(new base::files::FilePathWatcher);
149 FilePath style_sheet_file = profile_path_.AppendASCII(kStyleSheetDir) 149 FilePath style_sheet_file = profile_path_.AppendASCII(kStyleSheetDir)
150 .AppendASCII(kUserStyleSheetFile); 150 .AppendASCII(kUserStyleSheetFile);
151 if (!file_watcher_->Watch( 151 if (!file_watcher_->Watch(
152 style_sheet_file, 152 style_sheet_file,
153 loader_.get())) { 153 loader_.get())) {
154 LOG(ERROR) << "Failed to setup watch for " << style_sheet_file.value(); 154 LOG(ERROR) << "Failed to setup watch for " << style_sheet_file.value();
155 } 155 }
156 loader_->LoadStyleSheet(style_sheet_file); 156 loader_->LoadStyleSheet(style_sheet_file);
157 } 157 }
158 } 158 }
159 159
160 GURL UserStyleSheetWatcher::user_style_sheet() const { 160 GURL UserStyleSheetWatcher::user_style_sheet() const {
161 return loader_->user_style_sheet(); 161 return loader_->user_style_sheet();
162 } 162 }
163 163
164 void UserStyleSheetWatcher::Observe(NotificationType type, 164 void UserStyleSheetWatcher::Observe(NotificationType type,
165 const NotificationSource& source, const NotificationDetails& details) { 165 const NotificationSource& source, const NotificationDetails& details) {
166 DCHECK(type == NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB); 166 DCHECK(type == NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB);
167 loader_->NotifyLoaded(); 167 loader_->NotifyLoaded();
168 registrar_.RemoveAll(); 168 registrar_.RemoveAll();
169 } 169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698