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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { | 154 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
155 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 155 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
156 base::Bind(&UserStyleSheetWatcher::Init, this)); | 156 base::Bind(&UserStyleSheetWatcher::Init, this)); |
157 return; | 157 return; |
158 } | 158 } |
159 | 159 |
160 if (!file_watcher_.get()) { | 160 if (!file_watcher_.get()) { |
161 file_watcher_.reset(new FilePathWatcher); | 161 file_watcher_.reset(new FilePathWatcher); |
162 FilePath style_sheet_file = profile_path_.AppendASCII(kStyleSheetDir) | 162 FilePath style_sheet_file = profile_path_.AppendASCII(kStyleSheetDir) |
163 .AppendASCII(kUserStyleSheetFile); | 163 .AppendASCII(kUserStyleSheetFile); |
164 if (!file_watcher_->Watch( | 164 if (!file_watcher_->Watch(style_sheet_file, false, loader_.get())) |
165 style_sheet_file, | |
166 loader_.get())) { | |
167 LOG(ERROR) << "Failed to setup watch for " << style_sheet_file.value(); | 165 LOG(ERROR) << "Failed to setup watch for " << style_sheet_file.value(); |
168 } | |
169 loader_->LoadStyleSheet(style_sheet_file); | 166 loader_->LoadStyleSheet(style_sheet_file); |
170 } | 167 } |
171 } | 168 } |
172 | 169 |
173 GURL UserStyleSheetWatcher::user_style_sheet() const { | 170 GURL UserStyleSheetWatcher::user_style_sheet() const { |
174 return loader_->user_style_sheet(); | 171 return loader_->user_style_sheet(); |
175 } | 172 } |
176 | 173 |
177 void UserStyleSheetWatcher::Observe(int type, | 174 void UserStyleSheetWatcher::Observe(int type, |
178 const content::NotificationSource& source, | 175 const content::NotificationSource& source, |
179 const content::NotificationDetails& details) { | 176 const content::NotificationDetails& details) { |
180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
181 DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED); | 178 DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED); |
182 if (profile_->IsSameProfile(Profile::FromBrowserContext( | 179 if (profile_->IsSameProfile(Profile::FromBrowserContext( |
183 content::Source<WebContents>(source)->GetBrowserContext()))) { | 180 content::Source<WebContents>(source)->GetBrowserContext()))) { |
184 loader_->NotifyLoaded(); | 181 loader_->NotifyLoaded(); |
185 registrar_.RemoveAll(); | 182 registrar_.RemoveAll(); |
186 } | 183 } |
187 } | 184 } |
188 | 185 |
189 void UserStyleSheetWatcher::ShutdownOnUIThread() { | 186 void UserStyleSheetWatcher::ShutdownOnUIThread() { |
190 registrar_.RemoveAll(); | 187 registrar_.RemoveAll(); |
191 } | 188 } |
OLD | NEW |