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

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

Issue 12529024: Fix feedback log collection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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
« no previous file with comments | « chrome/browser/feedback/feedback_util.cc ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #include "ash/shell.h" 58 #include "ash/shell.h"
59 #include "ash/shell_delegate.h" 59 #include "ash/shell_delegate.h"
60 #include "base/file_util.h" 60 #include "base/file_util.h"
61 #include "base/path_service.h" 61 #include "base/path_service.h"
62 #include "chrome/browser/chromeos/cros/cros_library.h" 62 #include "chrome/browser/chromeos/cros/cros_library.h"
63 #include "chrome/browser/chromeos/drive/drive.pb.h" 63 #include "chrome/browser/chromeos/drive/drive.pb.h"
64 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" 64 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h"
65 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" 65 #include "chrome/browser/chromeos/drive/drive_file_system_util.h"
66 #include "chrome/browser/chromeos/drive/drive_system_service.h" 66 #include "chrome/browser/chromeos/drive/drive_system_service.h"
67 #include "chrome/browser/chromeos/login/user_manager.h" 67 #include "chrome/browser/chromeos/login/user_manager.h"
68 #include "chrome/browser/chromeos/system/syslogs_provider.h" 68 #include "chrome/browser/chromeos/system_logs/system_logs_fetcher.h"
69 #include "ui/aura/root_window.h" 69 #include "ui/aura/root_window.h"
70 #include "ui/aura/window.h" 70 #include "ui/aura/window.h"
71 #endif 71 #endif
72 72
73 using content::BrowserThread; 73 using content::BrowserThread;
74 using content::WebContents; 74 using content::WebContents;
75 using content::WebUIMessageHandler; 75 using content::WebUIMessageHandler;
76 using ui::WebDialogUI; 76 using ui::WebDialogUI;
77 77
78 namespace { 78 namespace {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 void HandleGetDialogDefaults(const ListValue* args); 259 void HandleGetDialogDefaults(const ListValue* args);
260 void HandleRefreshCurrentScreenshot(const ListValue* args); 260 void HandleRefreshCurrentScreenshot(const ListValue* args);
261 #if defined(OS_CHROMEOS) 261 #if defined(OS_CHROMEOS)
262 void HandleRefreshSavedScreenshots(const ListValue* args); 262 void HandleRefreshSavedScreenshots(const ListValue* args);
263 void RefreshSavedScreenshotsCallback( 263 void RefreshSavedScreenshotsCallback(
264 std::vector<std::string>* saved_screenshots); 264 std::vector<std::string>* saved_screenshots);
265 void GetMostRecentScreenshotsDrive( 265 void GetMostRecentScreenshotsDrive(
266 const base::FilePath& filepath, 266 const base::FilePath& filepath,
267 std::vector<std::string>* saved_screenshots, 267 std::vector<std::string>* saved_screenshots,
268 size_t max_saved, base::Closure callback); 268 size_t max_saved, base::Closure callback);
269 void StartSyslogsCollection();
269 #endif 270 #endif
270 void HandleSendReport(const ListValue* args); 271 void HandleSendReport(const ListValue* args);
271 void HandleCancel(const ListValue* args); 272 void HandleCancel(const ListValue* args);
272 void HandleOpenSystemTab(const ListValue* args); 273 void HandleOpenSystemTab(const ListValue* args);
273 274
274 void SetupScreenshotsSource(); 275 void SetupScreenshotsSource();
275 void ClobberScreenshotsSource(); 276 void ClobberScreenshotsSource();
276 277
277 void CancelFeedbackCollection();
278 void CloseFeedbackTab(); 278 void CloseFeedbackTab();
279 279
280 WebContents* tab_; 280 WebContents* tab_;
281 ScreenshotSource* screenshot_source_; 281 ScreenshotSource* screenshot_source_;
282 282
283 FeedbackData* feedback_data_; 283 scoped_refptr<FeedbackData> feedback_data_;
284 std::string target_tab_url_; 284 std::string target_tab_url_;
285 #if defined(OS_CHROMEOS) 285 #if defined(OS_CHROMEOS)
286 // Variables to track SyslogsProvider::RequestSyslogs.
287 CancelableTaskTracker::TaskId syslogs_task_id_;
288 CancelableTaskTracker syslogs_tracker_;
289
290 // Timestamp of when the feedback request was initiated. 286 // Timestamp of when the feedback request was initiated.
291 std::string timestamp_; 287 std::string timestamp_;
292 #endif 288 #endif
293 289
294 DISALLOW_COPY_AND_ASSIGN(FeedbackHandler); 290 DISALLOW_COPY_AND_ASSIGN(FeedbackHandler);
295 }; 291 };
296 292
297 content::WebUIDataSource* CreateFeedbackUIHTMLSource(bool successful_init) { 293 content::WebUIDataSource* CreateFeedbackUIHTMLSource(bool successful_init) {
298 content::WebUIDataSource* source = 294 content::WebUIDataSource* source =
299 content::WebUIDataSource::Create(chrome::kChromeUIFeedbackHost); 295 content::WebUIDataSource::Create(chrome::kChromeUIFeedbackHost);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 } 347 }
352 348
353 //////////////////////////////////////////////////////////////////////////////// 349 ////////////////////////////////////////////////////////////////////////////////
354 // 350 //
355 // FeedbackHandler 351 // FeedbackHandler
356 // 352 //
357 //////////////////////////////////////////////////////////////////////////////// 353 ////////////////////////////////////////////////////////////////////////////////
358 FeedbackHandler::FeedbackHandler(WebContents* tab) 354 FeedbackHandler::FeedbackHandler(WebContents* tab)
359 : tab_(tab), 355 : tab_(tab),
360 screenshot_source_(NULL), 356 screenshot_source_(NULL),
361 feedback_data_(NULL) 357 feedback_data_(NULL) {
362 #if defined(OS_CHROMEOS) 358 DCHECK(tab);
363 , syslogs_task_id_(CancelableTaskTracker::kBadTaskId) 359 }
364 #endif
365 {}
366 360
367 FeedbackHandler::~FeedbackHandler() { 361 FeedbackHandler::~FeedbackHandler() {
368 // Just in case we didn't send off feedback_data_ to SendReport
369 if (feedback_data_) {
370 // If we're deleting the report object, cancel feedback collection first
371 CancelFeedbackCollection();
372 delete feedback_data_;
373 }
374 // Make sure we don't leave any screenshot data around. 362 // Make sure we don't leave any screenshot data around.
375 FeedbackUtil::ClearScreenshotPng(); 363 FeedbackUtil::ClearScreenshotPng();
376 } 364 }
377 365
378 void FeedbackHandler::ClobberScreenshotsSource() { 366 void FeedbackHandler::ClobberScreenshotsSource() {
379 // Re-create our screenshots data source (this clobbers the last source) 367 // Re-create our screenshots data source (this clobbers the last source)
380 // setting the screenshot to NULL, effectively disabling the source 368 // setting the screenshot to NULL, effectively disabling the source
381 // TODO(rkc): Once there is a method to 'remove' a source, change this code 369 // TODO(rkc): Once there is a method to 'remove' a source, change this code
382 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext()); 370 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext());
383 content::URLDataSource::Add(profile, new ScreenshotSource(NULL, profile)); 371 content::URLDataSource::Add(profile, new ScreenshotSource(NULL, profile));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 base::Unretained(this))); 478 base::Unretained(this)));
491 web_ui()->RegisterMessageCallback("cancel", 479 web_ui()->RegisterMessageCallback("cancel",
492 base::Bind(&FeedbackHandler::HandleCancel, 480 base::Bind(&FeedbackHandler::HandleCancel,
493 base::Unretained(this))); 481 base::Unretained(this)));
494 web_ui()->RegisterMessageCallback("openSystemTab", 482 web_ui()->RegisterMessageCallback("openSystemTab",
495 base::Bind(&FeedbackHandler::HandleOpenSystemTab, 483 base::Bind(&FeedbackHandler::HandleOpenSystemTab,
496 base::Unretained(this))); 484 base::Unretained(this)));
497 } 485 }
498 486
499 void FeedbackHandler::HandleGetDialogDefaults(const ListValue*) { 487 void FeedbackHandler::HandleGetDialogDefaults(const ListValue*) {
500 // Will delete itself when feedback_data_->SendReport() is called.
501 feedback_data_ = new FeedbackData(); 488 feedback_data_ = new FeedbackData();
502 489
503 // Send back values which the dialog js needs initially. 490 // Send back values which the dialog js needs initially.
504 DictionaryValue dialog_defaults; 491 DictionaryValue dialog_defaults;
505 492
506 // Current url. 493 // Current url.
507 dialog_defaults.SetString("currentUrl", target_tab_url_); 494 dialog_defaults.SetString("currentUrl", target_tab_url_);
508 495
509 // Are screenshots disabled? 496 // Are screenshots disabled?
510 dialog_defaults.SetBoolean( 497 dialog_defaults.SetBoolean(
511 "disableScreenshots", 498 "disableScreenshots",
512 g_browser_process->local_state()->GetBoolean(prefs::kDisableScreenshots)); 499 g_browser_process->local_state()->GetBoolean(prefs::kDisableScreenshots));
513 500
514 // User e-mail 501 // User e-mail
515 std::string user_email = GetUserEmail(); 502 std::string user_email = GetUserEmail();
516 dialog_defaults.SetString("userEmail", user_email); 503 dialog_defaults.SetString("userEmail", user_email);
517 504
518 // Set email checkbox to checked by default for cros, unchecked for Chrome. 505 // Set email checkbox to checked by default for cros, unchecked for Chrome.
519 dialog_defaults.SetBoolean( 506 dialog_defaults.SetBoolean(
520 "emailCheckboxDefault", 507 "emailCheckboxDefault",
521 #if defined(OS_CHROMEOS) 508 #if defined(OS_CHROMEOS)
522 true); 509 true);
523 #else 510 #else
524 false); 511 false);
525 #endif 512 #endif
526 513
527 514
528 #if defined(OS_CHROMEOS) 515 #if defined(OS_CHROMEOS)
529 // Trigger the request for system information here. 516 feedback_data_->StartSyslogsCollection();
530 chromeos::system::SyslogsProvider* provider =
531 chromeos::system::SyslogsProvider::GetInstance();
532 if (provider) {
533 syslogs_task_id_ = provider->RequestSyslogs(
534 true, // don't compress.
535 chromeos::system::SyslogsProvider::SYSLOGS_FEEDBACK,
536 base::Bind(&FeedbackData::SyslogsComplete,
537 base::Unretained(feedback_data_)),
538 &syslogs_tracker_);
539 }
540 517
541 // On ChromeOS if the user's email is blank, it means we don't 518 // On ChromeOS if the user's email is blank, it means we don't
542 // have a logged in user, hence don't use saved screenshots. 519 // have a logged in user, hence don't use saved screenshots.
543 dialog_defaults.SetBoolean("useSaved", !user_email.empty()); 520 dialog_defaults.SetBoolean("useSaved", !user_email.empty());
544 #endif 521 #endif
545 522
546 web_ui()->CallJavascriptFunction("setupDialogDefaults", dialog_defaults); 523 web_ui()->CallJavascriptFunction("setupDialogDefaults", dialog_defaults);
547 } 524 }
548 525
549 void FeedbackHandler::HandleRefreshCurrentScreenshot(const ListValue*) { 526 void FeedbackHandler::HandleRefreshCurrentScreenshot(const ListValue*) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 // Get the image to send in the report. 595 // Get the image to send in the report.
619 ScreenshotDataPtr image_ptr; 596 ScreenshotDataPtr image_ptr;
620 if (!screenshot_path.empty() && screenshot_source_) 597 if (!screenshot_path.empty() && screenshot_source_)
621 image_ptr = screenshot_source_->GetCachedScreenshot(screenshot_path); 598 image_ptr = screenshot_source_->GetCachedScreenshot(screenshot_path);
622 599
623 #if defined(OS_CHROMEOS) 600 #if defined(OS_CHROMEOS)
624 std::string sys_info_checkbox; 601 std::string sys_info_checkbox;
625 (*i++)->GetAsString(&sys_info_checkbox); 602 (*i++)->GetAsString(&sys_info_checkbox);
626 bool send_sys_info = (sys_info_checkbox == "true"); 603 bool send_sys_info = (sys_info_checkbox == "true");
627 604
628 // If we aren't sending the sys_info, cancel the gathering of the syslogs.
629 if (!send_sys_info)
630 CancelFeedbackCollection();
631
632 std::string attached_filename; 605 std::string attached_filename;
633 std::string* attached_filedata = NULL; 606 std::string* attached_filedata = NULL;
634 // If we have an attached file, we'll still have more data in the list. 607 // If we have an attached file, we'll still have more data in the list.
635 if (i != list_value->end()) { 608 if (i != list_value->end()) {
636 (*i++)->GetAsString(&attached_filename); 609 (*i++)->GetAsString(&attached_filename);
637 if (base::FilePath::IsSeparator(attached_filename[0])) { 610 if (base::FilePath::IsSeparator(attached_filename[0])) {
638 // We have an attached filepath, not filename, hence we need read this 611 // We have an attached filepath, not filename, hence we need read this
639 // this file in chrome. We won't have any file data, skip over it. 612 // this file in chrome. We won't have any file data, skip over it.
640 i++; 613 i++;
641 } else { 614 } else {
642 std::string encoded_filedata; 615 std::string encoded_filedata;
643 attached_filedata = new std::string; 616 attached_filedata = new std::string;
644 (*i++)->GetAsString(&encoded_filedata); 617 (*i++)->GetAsString(&encoded_filedata);
645 if (!base::Base64Decode( 618 if (!base::Base64Decode(
646 base::StringPiece(encoded_filedata), attached_filedata)) { 619 base::StringPiece(encoded_filedata), attached_filedata)) {
647 LOG(ERROR) << "Unable to attach file: " << attached_filename; 620 LOG(ERROR) << "Unable to attach file: " << attached_filename;
648 // Clear the filename so feedback_util doesn't try to attach the file. 621 // Clear the filename so feedback_util doesn't try to attach the file.
649 attached_filename = ""; 622 attached_filename = "";
650 } 623 }
651 } 624 }
652 } 625 }
653 #endif 626 #endif
654 627
655 // Update the data in feedback_data_ so it can be sent 628 // TODO(rkc): We are not setting the category tag here since this
656 feedback_data_->UpdateData(Profile::FromWebUI(web_ui()) 629 // functionality is broken on the feedback server side. Fix this once the
657 , std::string() 630 // issue is resolved.
658 , page_url 631 feedback_data_->set_description(description);
659 , description 632 feedback_data_->set_image(image_ptr);
660 , user_email 633 feedback_data_->set_page_url(page_url);
661 , image_ptr 634 feedback_data_->set_profile(Profile::FromWebUI(web_ui()));
635 feedback_data_->set_user_email(user_email);
662 #if defined(OS_CHROMEOS) 636 #if defined(OS_CHROMEOS)
663 , send_sys_info 637 feedback_data_->set_attached_filedata(attached_filedata);
664 , false // sent_report 638 feedback_data_->set_attached_filename(attached_filename);
665 , timestamp_ 639 feedback_data_->set_send_sys_info(send_sys_info);
666 , attached_filename 640 feedback_data_->set_timestamp(timestamp_);
667 , attached_filedata
668 #endif 641 #endif
669 );
670 642
671 #if defined(OS_CHROMEOS) 643 // Signal the feedback object that the data from the feedback page has been
672 // If we don't require sys_info, or we have it, or we never requested it 644 // filled - the object will manage sending of the actual report.
673 // (because libcros failed to load), then send the report now. 645 feedback_data_->FeedbackPageDataComplete();
674 // Otherwise, the report will get sent when we receive sys_info.
675 if (!send_sys_info || feedback_data_->sys_info() != NULL ||
676 syslogs_task_id_ == CancelableTaskTracker::kBadTaskId) {
677 feedback_data_->SendReport();
678 }
679 #else
680 feedback_data_->SendReport();
681 #endif
682 // Lose the pointer to the FeedbackData object; the object will delete itself
683 // from SendReport, whether we called it, or will be called by the log
684 // completion routine.
685 feedback_data_ = NULL;
686 646
687 // Whether we sent the report, or if it will be sent by the Syslogs complete
688 // function, close our feedback tab anyway, we have no more use for it.
689 CloseFeedbackTab(); 647 CloseFeedbackTab();
690 } 648 }
691 649
692 void FeedbackHandler::HandleCancel(const ListValue*) { 650 void FeedbackHandler::HandleCancel(const ListValue*) {
693 CloseFeedbackTab(); 651 CloseFeedbackTab();
694 } 652 }
695 653
696 void FeedbackHandler::HandleOpenSystemTab(const ListValue* args) { 654 void FeedbackHandler::HandleOpenSystemTab(const ListValue* args) {
697 #if defined(OS_CHROMEOS) 655 #if defined(OS_CHROMEOS)
698 web_ui()->GetWebContents()->GetDelegate()->OpenURLFromTab( 656 web_ui()->GetWebContents()->GetDelegate()->OpenURLFromTab(
699 web_ui()->GetWebContents(), 657 web_ui()->GetWebContents(),
700 content::OpenURLParams(GURL(chrome::kChromeUISystemInfoURL), 658 content::OpenURLParams(GURL(chrome::kChromeUISystemInfoURL),
701 content::Referrer(), 659 content::Referrer(),
702 NEW_FOREGROUND_TAB, 660 NEW_FOREGROUND_TAB,
703 content::PAGE_TRANSITION_LINK, 661 content::PAGE_TRANSITION_LINK,
704 false)); 662 false));
705 #endif 663 #endif
706 } 664 }
707 665
708 void FeedbackHandler::CancelFeedbackCollection() {
709 #if defined(OS_CHROMEOS)
710 // Canceling a finished task ID or kBadTaskId is a noop.
711 syslogs_tracker_.TryCancel(syslogs_task_id_);
712 #endif
713 }
714
715 void FeedbackHandler::CloseFeedbackTab() { 666 void FeedbackHandler::CloseFeedbackTab() {
716 ClobberScreenshotsSource(); 667 ClobberScreenshotsSource();
717 tab_->GetDelegate()->CloseContents(tab_); 668 tab_->GetDelegate()->CloseContents(tab_);
718 } 669 }
719 670
720 //////////////////////////////////////////////////////////////////////////////// 671 ////////////////////////////////////////////////////////////////////////////////
721 // 672 //
722 // FeedbackUI 673 // FeedbackUI
723 // 674 //
724 //////////////////////////////////////////////////////////////////////////////// 675 ////////////////////////////////////////////////////////////////////////////////
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 screenshot_filepaths.begin() + sort_size, 712 screenshot_filepaths.begin() + sort_size,
762 screenshot_filepaths.end(), 713 screenshot_filepaths.end(),
763 ScreenshotTimestampComp); 714 ScreenshotTimestampComp);
764 for (size_t i = 0; i < sort_size; ++i) 715 for (size_t i = 0; i < sort_size; ++i)
765 saved_screenshots->push_back( 716 saved_screenshots->push_back(
766 std::string(ScreenshotSource::kScreenshotUrlRoot) + 717 std::string(ScreenshotSource::kScreenshotUrlRoot) +
767 std::string(ScreenshotSource::kScreenshotSaved) + 718 std::string(ScreenshotSource::kScreenshotSaved) +
768 screenshot_filepaths[i]); 719 screenshot_filepaths[i]);
769 } 720 }
770 #endif 721 #endif
OLDNEW
« no previous file with comments | « chrome/browser/feedback/feedback_util.cc ('k') | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698