| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 134 |
| 135 UserStyleSheetWatcher::UserStyleSheetWatcher(Profile* profile, | 135 UserStyleSheetWatcher::UserStyleSheetWatcher(Profile* profile, |
| 136 const FilePath& profile_path) | 136 const FilePath& profile_path) |
| 137 : RefcountedProfileKeyedService(content::BrowserThread::UI), | 137 : RefcountedProfileKeyedService(content::BrowserThread::UI), |
| 138 profile_(profile), | 138 profile_(profile), |
| 139 profile_path_(profile_path), | 139 profile_path_(profile_path), |
| 140 loader_(new UserStyleSheetLoader) { | 140 loader_(new UserStyleSheetLoader) { |
| 141 // Listen for when the first render view host is created. If we load | 141 // Listen for when the first render view host is created. If we load |
| 142 // too fast, the first tab won't hear the notification and won't get | 142 // too fast, the first tab won't hear the notification and won't get |
| 143 // the user style sheet. | 143 // the user style sheet. |
| 144 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, | 144 registrar_.Add(this, |
| 145 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
| 145 content::NotificationService::AllBrowserContextsAndSources()); | 146 content::NotificationService::AllBrowserContextsAndSources()); |
| 146 } | 147 } |
| 147 | 148 |
| 148 UserStyleSheetWatcher::~UserStyleSheetWatcher() { | 149 UserStyleSheetWatcher::~UserStyleSheetWatcher() { |
| 149 } | 150 } |
| 150 | 151 |
| 151 void UserStyleSheetWatcher::Init() { | 152 void UserStyleSheetWatcher::Init() { |
| 152 // Make sure we run on the file thread. | 153 // Make sure we run on the file thread. |
| 153 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { | 154 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
| 154 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 155 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 170 } | 171 } |
| 171 | 172 |
| 172 GURL UserStyleSheetWatcher::user_style_sheet() const { | 173 GURL UserStyleSheetWatcher::user_style_sheet() const { |
| 173 return loader_->user_style_sheet(); | 174 return loader_->user_style_sheet(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 void UserStyleSheetWatcher::Observe(int type, | 177 void UserStyleSheetWatcher::Observe(int type, |
| 177 const content::NotificationSource& source, | 178 const content::NotificationSource& source, |
| 178 const content::NotificationDetails& details) { | 179 const content::NotificationDetails& details) { |
| 179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 180 DCHECK(type == content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB); | 181 DCHECK(type == content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED); |
| 181 if (profile_->IsSameProfile(Profile::FromBrowserContext( | 182 if (profile_->IsSameProfile(Profile::FromBrowserContext( |
| 182 content::Source<WebContents>(source)->GetBrowserContext()))) { | 183 content::Source<WebContents>(source)->GetBrowserContext()))) { |
| 183 loader_->NotifyLoaded(); | 184 loader_->NotifyLoaded(); |
| 184 registrar_.RemoveAll(); | 185 registrar_.RemoveAll(); |
| 185 } | 186 } |
| 186 } | 187 } |
| 187 | 188 |
| 188 void UserStyleSheetWatcher::ShutdownOnUIThread() { | 189 void UserStyleSheetWatcher::ShutdownOnUIThread() { |
| 189 registrar_.RemoveAll(); | 190 registrar_.RemoveAll(); |
| 190 } | 191 } |
| OLD | NEW |