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

Side by Side Diff: chrome/browser/ui/webui/feedback_ui.cc

Issue 10196004: Changed ChromeURLDataManager to a ProfileKeyedService and made a Factory for it. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Made ChromeURLDataManager's destructor virtual Created 8 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
OLDNEW
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/ui/webui/feedback_ui.h" 5 #include "chrome/browser/ui/webui/feedback_ui.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "base/time.h" 17 #include "base/time.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/feedback/feedback_data.h" 19 #include "chrome/browser/feedback/feedback_data.h"
20 #include "chrome/browser/feedback/feedback_util.h" 20 #include "chrome/browser/feedback/feedback_util.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_list.h" 23 #include "chrome/browser/ui/browser_list.h"
24 #include "chrome/browser/ui/browser_window.h" 24 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
26 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
26 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 27 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
27 #include "chrome/browser/ui/webui/screenshot_source.h" 28 #include "chrome/browser/ui/webui/screenshot_source.h"
28 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" 29 #include "chrome/browser/ui/window_snapshot/window_snapshot.h"
29 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
30 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
31 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/navigation_controller.h" 33 #include "content/public/browser/navigation_controller.h"
33 #include "content/public/browser/navigation_entry.h" 34 #include "content/public/browser/navigation_entry.h"
34 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
35 #include "content/public/browser/web_ui.h" 36 #include "content/public/browser/web_ui.h"
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 } 298 }
298 // Make sure we don't leave any screenshot data around. 299 // Make sure we don't leave any screenshot data around.
299 FeedbackUtil::ClearScreenshotPng(); 300 FeedbackUtil::ClearScreenshotPng();
300 } 301 }
301 302
302 void FeedbackHandler::ClobberScreenshotsSource() { 303 void FeedbackHandler::ClobberScreenshotsSource() {
303 // Re-create our screenshots data source (this clobbers the last source) 304 // Re-create our screenshots data source (this clobbers the last source)
304 // setting the screenshot to NULL, effectively disabling the source 305 // setting the screenshot to NULL, effectively disabling the source
305 // TODO(rkc): Once there is a method to 'remove' a source, change this code 306 // TODO(rkc): Once there is a method to 'remove' a source, change this code
306 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext()); 307 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext());
307 profile->GetChromeURLDataManager()->AddDataSource(new ScreenshotSource(NULL)); 308 ChromeURLDataManager::AddDataSource(profile, new ScreenshotSource(NULL));
308 309
309 FeedbackUtil::ClearScreenshotPng(); 310 FeedbackUtil::ClearScreenshotPng();
310 } 311 }
311 312
312 void FeedbackHandler::SetupScreenshotsSource() { 313 void FeedbackHandler::SetupScreenshotsSource() {
313 // If we don't already have a screenshot source object created, create one. 314 // If we don't already have a screenshot source object created, create one.
314 if (!screenshot_source_) { 315 if (!screenshot_source_) {
315 screenshot_source_ = 316 screenshot_source_ =
316 new ScreenshotSource(FeedbackUtil::GetScreenshotPng()); 317 new ScreenshotSource(FeedbackUtil::GetScreenshotPng());
317 } 318 }
318 // Add the source to the data manager. 319 // Add the source to the data manager.
319 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext()); 320 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext());
320 profile->GetChromeURLDataManager()->AddDataSource(screenshot_source_); 321 ChromeURLDataManager::AddDataSource(profile, screenshot_source_);
321 } 322 }
322 323
323 bool FeedbackHandler::Init() { 324 bool FeedbackHandler::Init() {
324 std::string page_url; 325 std::string page_url;
325 if (tab_->GetController().GetActiveEntry()) { 326 if (tab_->GetController().GetActiveEntry()) {
326 page_url = tab_->GetController().GetActiveEntry()->GetURL().spec(); 327 page_url = tab_->GetController().GetActiveEntry()->GetURL().spec();
327 } 328 }
328 329
329 url_parse::Parsed parts; 330 url_parse::Parsed parts;
330 ParseStandardURL(page_url.c_str(), page_url.length(), &parts); 331 ParseStandardURL(page_url.c_str(), page_url.length(), &parts);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 FeedbackUI::FeedbackUI(content::WebUI* web_ui) : HtmlDialogUI(web_ui) { 580 FeedbackUI::FeedbackUI(content::WebUI* web_ui) : HtmlDialogUI(web_ui) {
580 FeedbackHandler* handler = new FeedbackHandler(web_ui->GetWebContents()); 581 FeedbackHandler* handler = new FeedbackHandler(web_ui->GetWebContents());
581 web_ui->AddMessageHandler(handler); 582 web_ui->AddMessageHandler(handler);
582 583
583 // The handler's init will determine whether we show the error html page. 584 // The handler's init will determine whether we show the error html page.
584 ChromeWebUIDataSource* html_source = 585 ChromeWebUIDataSource* html_source =
585 CreateFeedbackUIHTMLSource(handler->Init()); 586 CreateFeedbackUIHTMLSource(handler->Init());
586 587
587 // Set up the chrome://feedback/ source. 588 // Set up the chrome://feedback/ source.
588 Profile* profile = Profile::FromWebUI(web_ui); 589 Profile* profile = Profile::FromWebUI(web_ui);
589 profile->GetChromeURLDataManager()->AddDataSource(html_source); 590 ChromeURLDataManager::AddDataSource(profile, html_source);
590 } 591 }
591 592
592 #if defined(OS_CHROMEOS) 593 #if defined(OS_CHROMEOS)
593 // static 594 // static
594 void FeedbackUI::GetMostRecentScreenshots( 595 void FeedbackUI::GetMostRecentScreenshots(
595 const FilePath& filepath, 596 const FilePath& filepath,
596 std::vector<std::string>* saved_screenshots, 597 std::vector<std::string>* saved_screenshots,
597 size_t max_saved) { 598 size_t max_saved) {
598 file_util::FileEnumerator screenshots(filepath, false, 599 file_util::FileEnumerator screenshots(filepath, false,
599 file_util::FileEnumerator::FILES, 600 file_util::FileEnumerator::FILES,
600 std::string(kScreenshotPattern)); 601 std::string(kScreenshotPattern));
601 FilePath screenshot = screenshots.Next(); 602 FilePath screenshot = screenshots.Next();
602 603
603 std::vector<std::string> screenshot_filepaths; 604 std::vector<std::string> screenshot_filepaths;
604 while (!screenshot.empty()) { 605 while (!screenshot.empty()) {
605 screenshot_filepaths.push_back(screenshot.BaseName().value()); 606 screenshot_filepaths.push_back(screenshot.BaseName().value());
606 screenshot = screenshots.Next(); 607 screenshot = screenshots.Next();
607 } 608 }
608 609
609 size_t sort_size = std::min(max_saved, screenshot_filepaths.size()); 610 size_t sort_size = std::min(max_saved, screenshot_filepaths.size());
610 std::partial_sort(screenshot_filepaths.begin(), 611 std::partial_sort(screenshot_filepaths.begin(),
611 screenshot_filepaths.begin() + sort_size, 612 screenshot_filepaths.begin() + sort_size,
612 screenshot_filepaths.end(), 613 screenshot_filepaths.end(),
613 ScreenshotTimestampComp); 614 ScreenshotTimestampComp);
614 for (size_t i = 0; i < sort_size; ++i) 615 for (size_t i = 0; i < sort_size; ++i)
615 saved_screenshots->push_back(std::string(kSavedScreenshotsUrl) + 616 saved_screenshots->push_back(std::string(kSavedScreenshotsUrl) +
616 screenshot_filepaths[i]); 617 screenshot_filepaths[i]);
617 } 618 }
618 #endif 619 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/extensions/extensions_ui.cc ('k') | chrome/browser/ui/webui/flags_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698