diff options
author | achaulk@chromium.org <achaulk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-09 02:17:19 +0000 |
---|---|---|
committer | achaulk@chromium.org <achaulk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-09 02:17:19 +0000 |
commit | 1eab4e9e04c773022b3e24f251fa384396d48aa5 (patch) | |
tree | 1fc04e7225b99f5178d706bcaf65a13e9e4504f9 /chrome/browser/feedback | |
parent | 19fa2d9552faf1fb8c505e69f4683579239cd94f (diff) | |
download | chromium_src-1eab4e9e04c773022b3e24f251fa384396d48aa5.zip chromium_src-1eab4e9e04c773022b3e24f251fa384396d48aa5.tar.gz chromium_src-1eab4e9e04c773022b3e24f251fa384396d48aa5.tar.bz2 |
Move some common feedback files into src/components
BUG=359299
TEST=build works
Review URL: https://codereview.chromium.org/225183018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269152 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/feedback')
27 files changed, 75 insertions, 2295 deletions
diff --git a/chrome/browser/feedback/feedback_data.cc b/chrome/browser/feedback/feedback_data.cc deleted file mode 100644 index e5dde6a..0000000 --- a/chrome/browser/feedback/feedback_data.cc +++ /dev/null @@ -1,278 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/feedback/feedback_data.h" - -#include "base/file_util.h" -#include "base/json/json_string_value_serializer.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "base/values.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/chromeos/settings/cros_settings.h" -#include "chrome/browser/feedback/feedback_util.h" -#include "chrome/browser/feedback/tracing_manager.h" -#include "chrome/browser/profiles/profile_manager.h" -#include "content/public/browser/browser_thread.h" - -#if defined(USE_ASH) -#include "ash/shell.h" -#include "ash/shell_delegate.h" -#endif - -using content::BrowserThread; - -namespace { - -const char kMultilineIndicatorString[] = "<multiline>\n"; -const char kMultilineStartString[] = "---------- START ----------\n"; -const char kMultilineEndString[] = "---------- END ----------\n\n"; - -const size_t kFeedbackMaxLength = 4 * 1024; -const size_t kFeedbackMaxLineCount = 40; - -const char kTraceFilename[] = "tracing.zip\n"; -const char kPerformanceCategoryTag[] = "Performance"; - -const char kZipExt[] = ".zip"; - -const base::FilePath::CharType kLogsFilename[] = - FILE_PATH_LITERAL("system_logs.txt"); -const base::FilePath::CharType kHistogramsFilename[] = - FILE_PATH_LITERAL("histograms.txt"); - -// Converts the system logs into a string that we can compress and send -// with the report. This method only converts those logs that we want in -// the compressed zip file sent with the report, hence it ignores any logs -// below the size threshold of what we want compressed. -std::string LogsToString(const FeedbackData::SystemLogsMap& sys_info) { - std::string syslogs_string; - for (FeedbackData::SystemLogsMap::const_iterator it = sys_info.begin(); - it != sys_info.end(); ++it) { - std::string key = it->first; - std::string value = it->second; - - if (FeedbackData::BelowCompressionThreshold(value)) - continue; - - base::TrimString(key, "\n ", &key); - base::TrimString(value, "\n ", &value); - - if (value.find("\n") != std::string::npos) { - syslogs_string.append( - key + "=" + kMultilineIndicatorString + - kMultilineStartString + - value + "\n" + - kMultilineEndString); - } else { - syslogs_string.append(key + "=" + value + "\n"); - } - } - return syslogs_string; -} - -void ZipFile(const base::FilePath& filename, - const std::string& data, std::string* compressed_data) { - if (!feedback_util::ZipString(filename, data, compressed_data)) - compressed_data->clear(); -} - -void ZipLogs(const FeedbackData::SystemLogsMap& sys_info, - std::string* compressed_logs) { - DCHECK(compressed_logs); - std::string logs_string = LogsToString(sys_info); - if (logs_string.empty() || - !feedback_util::ZipString( - base::FilePath(kLogsFilename), logs_string, compressed_logs)) { - compressed_logs->clear(); - } -} - -void ZipHistograms(const std::string& histograms, - std::string* compressed_histograms) { - DCHECK(compressed_histograms); - if (histograms.empty() || - !feedback_util::ZipString( - base::FilePath(kHistogramsFilename), - histograms, - compressed_histograms)) { - compressed_histograms->clear(); - } -} - -} // namespace - -// static -bool FeedbackData::BelowCompressionThreshold(const std::string& content) { - if (content.length() > kFeedbackMaxLength) - return false; - const size_t line_count = std::count(content.begin(), content.end(), '\n'); - if (line_count > kFeedbackMaxLineCount) - return false; - return true; -} - -FeedbackData::FeedbackData() : profile_(NULL), - trace_id_(0), - feedback_page_data_complete_(false), - syslogs_compression_complete_(false), - histograms_compression_complete_(false), - attached_file_compression_complete_(false), - report_sent_(false) { -} - -FeedbackData::~FeedbackData() { -} - -void FeedbackData::OnFeedbackPageDataComplete() { - feedback_page_data_complete_ = true; - SendReport(); -} - -void FeedbackData::SetAndCompressSystemInfo( - scoped_ptr<FeedbackData::SystemLogsMap> sys_info) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - if (trace_id_ != 0) { - TracingManager* manager = TracingManager::Get(); - if (!manager || - !manager->GetTraceData( - trace_id_, - base::Bind(&FeedbackData::OnGetTraceData, this, trace_id_))) { - trace_id_ = 0; - } - } - - sys_info_ = sys_info.Pass(); - if (sys_info_.get()) { - std::string* compressed_logs_ptr = new std::string; - scoped_ptr<std::string> compressed_logs(compressed_logs_ptr); - BrowserThread::PostBlockingPoolTaskAndReply( - FROM_HERE, - base::Bind(&ZipLogs, - *sys_info_, - compressed_logs_ptr), - base::Bind(&FeedbackData::OnCompressLogsComplete, - this, - base::Passed(&compressed_logs))); - } -} - -void FeedbackData::SetAndCompressHistograms( - scoped_ptr<std::string> histograms) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - histograms_ = histograms.Pass(); - if (histograms_.get()) { - std::string* compressed_histograms_ptr = new std::string; - scoped_ptr<std::string> compressed_histograms(compressed_histograms_ptr); - BrowserThread::PostBlockingPoolTaskAndReply( - FROM_HERE, - base::Bind(&ZipHistograms, - *histograms_, - compressed_histograms_ptr), - base::Bind(&FeedbackData::OnCompressHistogramsComplete, - this, - base::Passed(&compressed_histograms))); - } -} - -void FeedbackData::AttachAndCompressFileData( - scoped_ptr<std::string> attached_filedata) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - attached_filedata_ = attached_filedata.Pass(); - - if (!attached_filename_.empty() && attached_filedata_.get()) { - std::string* compressed_file_ptr = new std::string; - scoped_ptr<std::string> compressed_file(compressed_file_ptr); -#if defined(OS_WIN) - base::FilePath attached_file(base::UTF8ToWide(attached_filename_)); -#else - base::FilePath attached_file(attached_filename_); -#endif - BrowserThread::PostBlockingPoolTaskAndReply( - FROM_HERE, - base::Bind(&ZipFile, - attached_file, - *(attached_filedata_.get()), - compressed_file_ptr), - base::Bind(&FeedbackData::OnCompressFileComplete, - this, - base::Passed(&compressed_file))); - } -} - -void FeedbackData::OnGetTraceData( - int trace_id, - scoped_refptr<base::RefCountedString> trace_data) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - TracingManager* manager = TracingManager::Get(); - if (manager) - manager->DiscardTraceData(trace_id); - - scoped_ptr<std::string> data(new std::string); - data->swap(trace_data->data()); - - attached_filename_ = kTraceFilename; - attached_filedata_ = data.Pass(); - attached_file_compression_complete_ = true; - trace_id_ = 0; - - set_category_tag(kPerformanceCategoryTag); - - SendReport(); -} - -void FeedbackData::OnCompressLogsComplete( - scoped_ptr<std::string> compressed_logs) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - compressed_logs_ = compressed_logs.Pass(); - syslogs_compression_complete_ = true; - - SendReport(); -} - -void FeedbackData::OnCompressHistogramsComplete( - scoped_ptr<std::string> compressed_histograms) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - compressed_histograms_ = compressed_histograms.Pass(); - histograms_compression_complete_ = true; - - SendReport(); -} - -void FeedbackData::OnCompressFileComplete( - scoped_ptr<std::string> compressed_file) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - if (compressed_file.get()) { - attached_filedata_ = compressed_file.Pass(); - attached_filename_.append(kZipExt); - attached_file_compression_complete_ = true; - } else { - attached_filename_.clear(); - attached_filedata_.reset(NULL); - } - - SendReport(); -} - -bool FeedbackData::IsDataComplete() { - return (!sys_info_.get() || syslogs_compression_complete_) && - (!histograms_.get() || histograms_compression_complete_) && - (!attached_filedata_.get() || attached_file_compression_complete_) && - !trace_id_ && - feedback_page_data_complete_; -} - -void FeedbackData::SendReport() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (IsDataComplete() && !report_sent_) { - report_sent_ = true; - feedback_util::SendReport(this); - } -} diff --git a/chrome/browser/feedback/feedback_data.h b/chrome/browser/feedback/feedback_data.h deleted file mode 100644 index bc566f5..0000000 --- a/chrome/browser/feedback/feedback_data.h +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_FEEDBACK_FEEDBACK_DATA_H_ -#define CHROME_BROWSER_FEEDBACK_FEEDBACK_DATA_H_ - -#include <map> -#include <string> -#include <vector> - -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "url/gurl.h" - -namespace base { -class FilePath; -class RefCountedString; -} -class Profile; - -class FeedbackData : public base::RefCountedThreadSafe<FeedbackData> { - public: - typedef std::map<std::string, std::string> SystemLogsMap; - - // Determine if the given feedback value is small enough to not need to - // be compressed. - static bool BelowCompressionThreshold(const std::string& content); - - FeedbackData(); - - // Called once we've updated all the data from the feedback page. - void OnFeedbackPageDataComplete(); - - // Sets the system information for this instance and kicks off its - // compression. - void SetAndCompressSystemInfo(scoped_ptr<SystemLogsMap> sys_info); - - // Sets the histograms for this instance and kicks off its - // compression. - void SetAndCompressHistograms(scoped_ptr<std::string> histograms); - - // Sets the attached file data and kicks off its compression. - void AttachAndCompressFileData(scoped_ptr<std::string> attached_filedata); - - // Called once we have compressed our system logs. - void OnCompressLogsComplete(scoped_ptr<std::string> compressed_logs); - - // Called once we have compressed our histograms. - void OnCompressHistogramsComplete( - scoped_ptr<std::string> compressed_histograms); - - // Called once we have compressed our attached file. - void OnCompressFileComplete(scoped_ptr<std::string> compressed_file); - - // Returns true if we've completed all the tasks needed before we can send - // feedback - at this time this is includes getting the feedback page data - // and compressing the system logs. - bool IsDataComplete(); - - // Sends the feedback report if we have all our data complete. - void SendReport(); - - // Getters - Profile* profile() const { return profile_; } - const std::string& category_tag() const { return category_tag_; } - const std::string& page_url() const { return page_url_; } - const std::string& description() const { return description_; } - const std::string& user_email() const { return user_email_; } - std::string* image() const { return image_.get(); } - const std::string attached_filename() const { return attached_filename_; } - const std::string attached_file_uuid() const { return attached_file_uuid_; } - std::string* attached_filedata() const { return attached_filedata_.get(); } - const std::string screenshot_uuid() const { return screenshot_uuid_; } - int trace_id() const { return trace_id_; } - SystemLogsMap* sys_info() const { return sys_info_.get(); } - std::string* compressed_logs() const { return compressed_logs_.get(); } - std::string* histograms() const { return histograms_.get(); } - std::string* compressed_histograms() const { - return compressed_histograms_.get(); - } - - // Setters - void set_profile(Profile* profile) { profile_ = profile; } - void set_category_tag(const std::string& category_tag) { - category_tag_ = category_tag; - } - void set_page_url(const std::string& page_url) { page_url_ = page_url; } - void set_description(const std::string& description) { - description_ = description; - } - void set_user_email(const std::string& user_email) { - user_email_ = user_email; - } - void set_image(scoped_ptr<std::string> image) { image_ = image.Pass(); } - void set_attached_filename(const std::string& attached_filename) { - attached_filename_ = attached_filename; - } - void set_attached_file_uuid(const std::string& uuid) { - attached_file_uuid_ = uuid; - } - void set_screenshot_uuid(const std::string& uuid) { - screenshot_uuid_ = uuid; - } - void set_trace_id(int trace_id) { trace_id_ = trace_id; } - - private: - friend class base::RefCountedThreadSafe<FeedbackData>; - - virtual ~FeedbackData(); - - void OnGetTraceData(int trace_id, - scoped_refptr<base::RefCountedString> trace_data); - - Profile* profile_; - - std::string category_tag_; - std::string page_url_; - std::string description_; - std::string user_email_; - scoped_ptr<std::string> image_; - std::string attached_filename_; - scoped_ptr<std::string> attached_filedata_; - - std::string attached_file_uuid_; - std::string screenshot_uuid_; - - int trace_id_; - - scoped_ptr<SystemLogsMap> sys_info_; - scoped_ptr<std::string> compressed_logs_; - - scoped_ptr<std::string> histograms_; - scoped_ptr<std::string> compressed_histograms_; - - // TODO(rkc): Refactor compressing logic into a simpler common implementation. - bool feedback_page_data_complete_; - bool syslogs_compression_complete_; - bool histograms_compression_complete_; - bool attached_file_compression_complete_; - bool report_sent_; - - DISALLOW_COPY_AND_ASSIGN(FeedbackData); -}; - -#endif // CHROME_BROWSER_FEEDBACK_FEEDBACK_DATA_H_ diff --git a/chrome/browser/feedback/feedback_profile_observer.cc b/chrome/browser/feedback/feedback_profile_observer.cc index a08b653..63d5ac7 100644 --- a/chrome/browser/feedback/feedback_profile_observer.cc +++ b/chrome/browser/feedback/feedback_profile_observer.cc @@ -6,10 +6,10 @@ #include "base/callback.h" #include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/feedback/feedback_report.h" -#include "chrome/browser/feedback/feedback_uploader.h" -#include "chrome/browser/feedback/feedback_uploader_factory.h" #include "chrome/browser/profiles/profile.h" +#include "components/feedback/feedback_report.h" +#include "components/feedback/feedback_uploader.h" +#include "components/feedback/feedback_uploader_factory.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_service.h" diff --git a/chrome/browser/feedback/feedback_report.cc b/chrome/browser/feedback/feedback_report.cc deleted file mode 100644 index 8518d2b..0000000 --- a/chrome/browser/feedback/feedback_report.cc +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/feedback/feedback_report.h" - -#include "base/file_util.h" -#include "base/files/file_enumerator.h" -#include "base/files/important_file_writer.h" -#include "base/guid.h" -#include "base/strings/string_number_conversions.h" -#include "base/threading/sequenced_worker_pool.h" -#include "net/base/directory_lister.h" - -namespace { - -const base::FilePath::CharType kFeedbackReportFilenameWildcard[] = - FILE_PATH_LITERAL("Feedback Report.*"); - -const char kFeedbackReportFilenamePrefix[] = "Feedback Report."; - -void WriteReportOnBlockingPool(const base::FilePath reports_path, - const base::FilePath& file, - const std::string& data) { - DCHECK(reports_path.IsParent(file)); - if (!base::DirectoryExists(reports_path)) { - base::File::Error error; - if (!base::CreateDirectoryAndGetError(reports_path, &error)) - return; - } - base::ImportantFileWriter::WriteFileAtomically(file, data); -} - -} // namespace - -namespace feedback { - -FeedbackReport::FeedbackReport( - const base::FilePath& path, - const base::Time& upload_at, - const std::string& data, - scoped_refptr<base::SequencedTaskRunner> task_runner) - : reports_path_(path), - upload_at_(upload_at), - data_(data), - reports_task_runner_(task_runner) { - if (reports_path_.empty()) - return; - file_ = reports_path_.AppendASCII( - kFeedbackReportFilenamePrefix + base::GenerateGUID()); - - reports_task_runner_->PostTask(FROM_HERE, base::Bind( - &WriteReportOnBlockingPool, reports_path_, file_, data_)); -} - -FeedbackReport::~FeedbackReport() {} - -void FeedbackReport::DeleteReportOnDisk() { - reports_task_runner_->PostTask(FROM_HERE, base::Bind( - base::IgnoreResult(&base::DeleteFile), file_, false)); -} - -// static -void FeedbackReport::LoadReportsAndQueue( - const base::FilePath& user_dir, QueueCallback callback) { - if (user_dir.empty()) - return; - - base::FileEnumerator enumerator(user_dir, - false, - base::FileEnumerator::FILES, - kFeedbackReportFilenameWildcard); - for (base::FilePath name = enumerator.Next(); - !name.empty(); - name = enumerator.Next()) { - std::string data; - if (ReadFileToString(name, &data)) - callback.Run(data); - base::DeleteFile(name, false); - } -} - -} // namespace feedback diff --git a/chrome/browser/feedback/feedback_report.h b/chrome/browser/feedback/feedback_report.h deleted file mode 100644 index 92914d1..0000000 --- a/chrome/browser/feedback/feedback_report.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_FEEDBACK_FEEDBACK_REPORT_H_ -#define CHROME_BROWSER_FEEDBACK_FEEDBACK_REPORT_H_ - -#include <string> - -#include "base/basictypes.h" -#include "base/callback_forward.h" -#include "base/files/file_path.h" -#include "base/memory/ref_counted.h" -#include "base/time/time.h" - -namespace base { -class SequencedTaskRunner; -} - -namespace feedback { - -typedef base::Callback<void(const std::string&)> QueueCallback; - -// This class holds a feedback report. Once a report is created, a disk backup -// for it is created automatically. This backup needs to explicitly be -// deleted by calling DeleteReportOnDisk. -class FeedbackReport : public base::RefCounted<FeedbackReport> { - public: - FeedbackReport(const base::FilePath& path, - const base::Time& upload_at, - const std::string& data, - scoped_refptr<base::SequencedTaskRunner> task_runner); - - // Stops the disk write of the report and deletes the report file if already - // written. - void DeleteReportOnDisk(); - - const base::Time& upload_at() const { return upload_at_; } - const std::string& data() const { return data_; } - - // Loads the reports still on disk and queues then using the given callback. - // This call blocks on the file reads. - static void LoadReportsAndQueue(const base::FilePath& user_dir, - QueueCallback callback); - - private: - friend class base::RefCounted<FeedbackReport>; - virtual ~FeedbackReport(); - - // Name of the file corresponding to this report. - base::FilePath file_; - - base::FilePath reports_path_; - base::Time upload_at_; // Upload this report at or after this time. - std::string data_; - - scoped_refptr<base::SequencedTaskRunner> reports_task_runner_; - - DISALLOW_COPY_AND_ASSIGN(FeedbackReport); -}; - -} // namespace feedback - -#endif // CHROME_BROWSER_FEEDBACK_FEEDBACK_REPORT_H_ diff --git a/chrome/browser/feedback/feedback_uploader.cc b/chrome/browser/feedback/feedback_uploader.cc deleted file mode 100644 index 1798e3bf..0000000 --- a/chrome/browser/feedback/feedback_uploader.cc +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/feedback/feedback_uploader.h" - -#include "base/callback.h" -#include "base/command_line.h" -#include "base/files/file_path.h" -#include "base/sequenced_task_runner.h" -#include "base/task_runner_util.h" -#include "base/threading/sequenced_worker_pool.h" -#include "chrome/browser/feedback/feedback_report.h" - -namespace feedback { -namespace { - -const char kFeedbackPostUrl[] = - "https://www.google.com/tools/feedback/chrome/__submit"; - -const int64 kRetryDelayMinutes = 60; - -const base::FilePath::CharType kFeedbackReportPath[] = - FILE_PATH_LITERAL("Feedback Reports"); - -} // namespace - -bool FeedbackUploader::ReportsUploadTimeComparator::operator()( - FeedbackReport* a, FeedbackReport* b) const { - return a->upload_at() > b->upload_at(); -} - -FeedbackUploader::FeedbackUploader(const base::FilePath& path, - base::SequencedWorkerPool* pool) - : report_path_(path.Append(kFeedbackReportPath)), - retry_delay_(base::TimeDelta::FromMinutes(kRetryDelayMinutes)), - url_(kFeedbackPostUrl), - pool_(pool) { - dispatch_callback_ = base::Bind(&FeedbackUploader::DispatchReport, - AsWeakPtr()); -} - -FeedbackUploader::~FeedbackUploader() {} - -void FeedbackUploader::QueueReport(const std::string& data) { - QueueReportWithDelay(data, base::TimeDelta()); -} - -void FeedbackUploader::UpdateUploadTimer() { - if (reports_queue_.empty()) - return; - - scoped_refptr<FeedbackReport> report = reports_queue_.top(); - base::Time now = base::Time::Now(); - if (report->upload_at() <= now) { - reports_queue_.pop(); - dispatch_callback_.Run(report->data()); - report->DeleteReportOnDisk(); - } else { - // Stop the old timer and start an updated one. - if (upload_timer_.IsRunning()) - upload_timer_.Stop(); - upload_timer_.Start( - FROM_HERE, report->upload_at() - now, this, - &FeedbackUploader::UpdateUploadTimer); - } -} - -void FeedbackUploader::RetryReport(const std::string& data) { - QueueReportWithDelay(data, retry_delay_); -} - -void FeedbackUploader::QueueReportWithDelay(const std::string& data, - base::TimeDelta delay) { - // Uses a BLOCK_SHUTDOWN file task runner because we really don't want to - // lose reports. - scoped_refptr<base::SequencedTaskRunner> task_runner = - pool_->GetSequencedTaskRunnerWithShutdownBehavior( - pool_->GetSequenceToken(), - base::SequencedWorkerPool::BLOCK_SHUTDOWN); - - reports_queue_.push(new FeedbackReport(report_path_, - base::Time::Now() + delay, - data, - task_runner)); - UpdateUploadTimer(); -} - -void FeedbackUploader::setup_for_test( - const ReportDataCallback& dispatch_callback, - const base::TimeDelta& retry_delay) { - dispatch_callback_ = dispatch_callback; - retry_delay_ = retry_delay; -} - -} // namespace feedback diff --git a/chrome/browser/feedback/feedback_uploader.h b/chrome/browser/feedback/feedback_uploader.h deleted file mode 100644 index 2bef774..0000000 --- a/chrome/browser/feedback/feedback_uploader.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_H_ -#define CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_H_ - -#include <queue> -#include <string> - -#include "base/basictypes.h" -#include "base/file_util.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" -#include "base/time/time.h" -#include "base/timer/timer.h" - -namespace feedback { - -typedef base::Callback<void(const std::string&)> ReportDataCallback; - -class FeedbackReport; - -// FeedbackUploader is used to add a feedback report to the queue of reports -// being uploaded. In case uploading a report fails, it is written to disk and -// tried again when it's turn comes up next in the queue. -class FeedbackUploader : public base::SupportsWeakPtr<FeedbackUploader> { - public: - explicit FeedbackUploader(const base::FilePath& path, - base::SequencedWorkerPool* pool); - virtual ~FeedbackUploader(); - - // Queues a report for uploading. - void QueueReport(const std::string& data); - - base::FilePath GetFeedbackReportsPath() { return report_path_; } - - protected: - friend class FeedbackUploaderTest; - struct ReportsUploadTimeComparator { - bool operator()(FeedbackReport* a, FeedbackReport* b) const; - }; - - // Dispatches the report to be uploaded. - virtual void DispatchReport(const std::string& data) = 0; - - // Update our timer for uploading the next report. - void UpdateUploadTimer(); - - // Requeue this report with a delay. - void RetryReport(const std::string& data); - - void QueueReportWithDelay(const std::string& data, base::TimeDelta delay); - - void setup_for_test(const ReportDataCallback& dispatch_callback, - const base::TimeDelta& retry_delay); - - base::FilePath report_path_; - // Timer to upload the next report at. - base::OneShotTimer<FeedbackUploader> upload_timer_; - // Priority queue of reports prioritized by the time the report is supposed - // to be uploaded at. - std::priority_queue<scoped_refptr<FeedbackReport>, - std::vector<scoped_refptr<FeedbackReport> >, - ReportsUploadTimeComparator> reports_queue_; - - ReportDataCallback dispatch_callback_; - base::TimeDelta retry_delay_; - std::string url_; - base::SequencedWorkerPool* pool_; - - DISALLOW_COPY_AND_ASSIGN(FeedbackUploader); -}; - -} // namespace feedback - -#endif // CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_H_ diff --git a/chrome/browser/feedback/feedback_uploader_chrome.cc b/chrome/browser/feedback/feedback_uploader_chrome.cc deleted file mode 100644 index 7a0be8f..0000000 --- a/chrome/browser/feedback/feedback_uploader_chrome.cc +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/feedback/feedback_uploader_chrome.h" - -#include "base/callback.h" -#include "base/command_line.h" -#include "base/files/file_path.h" -#include "base/task_runner_util.h" -#include "base/threading/sequenced_worker_pool.h" -#include "chrome/browser/feedback/feedback_report.h" -#include "chrome/browser/feedback/feedback_uploader_delegate.h" -#include "chrome/common/chrome_switches.h" -#include "content/public/browser/browser_context.h" -#include "content/public/browser/browser_thread.h" -#include "net/base/load_flags.h" -#include "net/url_request/url_fetcher.h" -#include "url/gurl.h" - -using content::BrowserThread; - -namespace feedback { -namespace { - -const char kProtoBufMimeType[] = "application/x-protobuf"; - -} // namespace - -FeedbackUploaderChrome::FeedbackUploaderChrome( - content::BrowserContext* context) - : FeedbackUploader(context ? context->GetPath() : base::FilePath(), - BrowserThread::GetBlockingPool()), - context_(context) { - CHECK(context_); - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kFeedbackServer)) - url_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( - switches::kFeedbackServer); -} - -void FeedbackUploaderChrome::DispatchReport(const std::string& data) { - GURL post_url(url_); - - net::URLFetcher* fetcher = net::URLFetcher::Create( - post_url, net::URLFetcher::POST, - new FeedbackUploaderDelegate( - data, - base::Bind(&FeedbackUploaderChrome::UpdateUploadTimer, AsWeakPtr()), - base::Bind(&FeedbackUploaderChrome::RetryReport, AsWeakPtr()))); - - fetcher->SetUploadData(std::string(kProtoBufMimeType), data); - fetcher->SetRequestContext(context_->GetRequestContext()); - fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | - net::LOAD_DO_NOT_SEND_COOKIES); - fetcher->Start(); -} - -} // namespace feedback diff --git a/chrome/browser/feedback/feedback_uploader_chrome.h b/chrome/browser/feedback/feedback_uploader_chrome.h deleted file mode 100644 index dc4ac59..0000000 --- a/chrome/browser/feedback/feedback_uploader_chrome.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_CHROME_H_ -#define CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_CHROME_H_ - -#include "chrome/browser/feedback/feedback_uploader.h" - -#include "components/keyed_service/core/keyed_service.h" - -namespace content { -class BrowserContext; -} - -namespace feedback { - -class FeedbackUploaderChrome : public FeedbackUploader, - public KeyedService { - public: - explicit FeedbackUploaderChrome(content::BrowserContext* context); - - virtual void DispatchReport(const std::string& data) OVERRIDE; - - private: - // Browser context this uploader was created for. - content::BrowserContext* context_; - - DISALLOW_COPY_AND_ASSIGN(FeedbackUploaderChrome); -}; - -} // namespace feedback - -#endif // CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_CHROME_H_ diff --git a/chrome/browser/feedback/feedback_uploader_delegate.cc b/chrome/browser/feedback/feedback_uploader_delegate.cc deleted file mode 100644 index 28256dd..0000000 --- a/chrome/browser/feedback/feedback_uploader_delegate.cc +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/feedback/feedback_uploader_delegate.h" - -#include <sstream> - -#include "base/logging.h" -#include "net/url_request/url_fetcher.h" -#include "url/gurl.h" - -namespace feedback { -namespace { - -const int kHttpPostSuccessNoContent = 204; -const int kHttpPostFailNoConnection = -1; -const int kHttpPostFailClientError = 400; -const int kHttpPostFailServerError = 500; - -} // namespace - -FeedbackUploaderDelegate::FeedbackUploaderDelegate( - const std::string& post_body, - const base::Closure& success_callback, - const ReportDataCallback& error_callback) - : post_body_(post_body), - success_callback_(success_callback), - error_callback_(error_callback) { -} - -FeedbackUploaderDelegate::~FeedbackUploaderDelegate() {} - -void FeedbackUploaderDelegate::OnURLFetchComplete( - const net::URLFetcher* source) { - scoped_ptr<const net::URLFetcher> source_scoper(source); - - std::stringstream error_stream; - int response_code = source->GetResponseCode(); - if (response_code == kHttpPostSuccessNoContent) { - error_stream << "Success"; - success_callback_.Run(); - } else { - // Process the error for debug output - if (response_code == kHttpPostFailNoConnection) { - error_stream << "No connection to server."; - } else if ((response_code > kHttpPostFailClientError) && - (response_code < kHttpPostFailServerError)) { - error_stream << "Client error: HTTP response code " << response_code; - } else if (response_code > kHttpPostFailServerError) { - error_stream << "Server error: HTTP response code " << response_code; - } else { - error_stream << "Unknown error: HTTP response code " << response_code; - } - error_callback_.Run(post_body_); - } - - LOG(WARNING) << "FEEDBACK: Submission to feedback server (" - << source->GetURL() << ") status: " << error_stream.str(); - - // This instance won't be used for anything else, delete us. - delete this; -} - -} // namespace feedback diff --git a/chrome/browser/feedback/feedback_uploader_delegate.h b/chrome/browser/feedback/feedback_uploader_delegate.h deleted file mode 100644 index 67d23a7..0000000 --- a/chrome/browser/feedback/feedback_uploader_delegate.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_DELEGATE_H_ -#define CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_DELEGATE_H_ - -#include <string> - -#include "base/basictypes.h" -#include "base/callback.h" -#include "chrome/browser/feedback/feedback_uploader.h" -#include "net/url_request/url_fetcher_delegate.h" - -namespace feedback { - -// FeedbackUploaderDelegate is a simple http uploader for a feedback report. On -// succes or failure, it deletes itself, but on failure it also notifies the -// error callback specified when constructing the class instance. -class FeedbackUploaderDelegate : public net::URLFetcherDelegate { - public: - FeedbackUploaderDelegate(const std::string& post_body, - const base::Closure& success_callback, - const ReportDataCallback& error_callback); - virtual ~FeedbackUploaderDelegate(); - - private: - // Overridden from net::URLFetcherDelegate. - virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; - - std::string post_body_; - base::Closure success_callback_; - ReportDataCallback error_callback_; - - DISALLOW_COPY_AND_ASSIGN(FeedbackUploaderDelegate); -}; - -} // namespace feedback - -#endif // CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_DELEGATE_H_ diff --git a/chrome/browser/feedback/feedback_uploader_factory.cc b/chrome/browser/feedback/feedback_uploader_factory.cc deleted file mode 100644 index bc20ecc..0000000 --- a/chrome/browser/feedback/feedback_uploader_factory.cc +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/feedback/feedback_uploader_factory.h" - -#include "base/memory/singleton.h" -#include "chrome/browser/feedback/feedback_uploader.h" -#include "chrome/browser/feedback/feedback_uploader_chrome.h" -#include "chrome/browser/profiles/incognito_helpers.h" -#include "components/keyed_service/content/browser_context_dependency_manager.h" - -namespace feedback { - -// static -FeedbackUploaderFactory* FeedbackUploaderFactory::GetInstance() { - return Singleton<FeedbackUploaderFactory>::get(); -} - -// static -FeedbackUploader* FeedbackUploaderFactory::GetForBrowserContext( - content::BrowserContext* context) { - return static_cast<FeedbackUploaderChrome*>( - GetInstance()->GetServiceForBrowserContext(context, true)); -} - -FeedbackUploaderFactory::FeedbackUploaderFactory() - : BrowserContextKeyedServiceFactory( - "feedback::FeedbackUploader", - BrowserContextDependencyManager::GetInstance()) {} - -FeedbackUploaderFactory::~FeedbackUploaderFactory() {} - -KeyedService* FeedbackUploaderFactory::BuildServiceInstanceFor( - content::BrowserContext* context) const { - return new FeedbackUploaderChrome(context); -} - -content::BrowserContext* FeedbackUploaderFactory::GetBrowserContextToUse( - content::BrowserContext* context) const { - return chrome::GetBrowserContextOwnInstanceInIncognito(context); -} - -} // namespace feedback diff --git a/chrome/browser/feedback/feedback_uploader_factory.h b/chrome/browser/feedback/feedback_uploader_factory.h deleted file mode 100644 index 2823c09..0000000 --- a/chrome/browser/feedback/feedback_uploader_factory.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_FACTORY_H_ -#define CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_FACTORY_H_ - -#include "components/keyed_service/content/browser_context_keyed_service_factory.h" - -template<typename T> struct DefaultSingletonTraits; - -namespace content { -class BrowserContext; -} - -namespace feedback { - -class FeedbackUploader; - -// Singleton that owns the FeedbackUploaders and associates them with profiles; -class FeedbackUploaderFactory : public BrowserContextKeyedServiceFactory { - public: - // Returns singleton instance of FeedbackUploaderFactory. - static FeedbackUploaderFactory* GetInstance(); - - // Returns the Feedback Uploader associated with |context|. - static FeedbackUploader* GetForBrowserContext( - content::BrowserContext* context); - - private: - friend struct DefaultSingletonTraits<FeedbackUploaderFactory>; - - FeedbackUploaderFactory(); - virtual ~FeedbackUploaderFactory(); - - // BrowserContextKeyedServiceFactory overrides: - virtual KeyedService* BuildServiceInstanceFor( - content::BrowserContext* context) const OVERRIDE; - virtual content::BrowserContext* GetBrowserContextToUse( - content::BrowserContext* context) const OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(FeedbackUploaderFactory); -}; - -} // namespace feedback - -#endif // CHROME_BROWSER_FEEDBACK_FEEDBACK_UPLOADER_FACTORY_H_ diff --git a/chrome/browser/feedback/feedback_uploader_unittest.cc b/chrome/browser/feedback/feedback_uploader_unittest.cc deleted file mode 100644 index b504be0..0000000 --- a/chrome/browser/feedback/feedback_uploader_unittest.cc +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/feedback/feedback_uploader.h" - -#include <set> - -#include "base/bind.h" -#include "base/message_loop/message_loop.h" -#include "base/run_loop.h" -#include "chrome/browser/feedback/feedback_uploader_chrome.h" -#include "chrome/browser/feedback/feedback_uploader_factory.h" -#include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -const char kReportOne[] = "one"; -const char kReportTwo[] = "two"; -const char kReportThree[] = "three"; -const char kReportFour[] = "four"; -const char kReportFive[] = "five"; - -const base::TimeDelta kRetryDelayForTest = - base::TimeDelta::FromMilliseconds(100); - -KeyedService* CreateFeedbackUploaderService(content::BrowserContext* context) { - return new feedback::FeedbackUploaderChrome( - Profile::FromBrowserContext(context)); -} - -} // namespace - -namespace feedback { - -class FeedbackUploaderTest : public testing::Test { - protected: - FeedbackUploaderTest() - : ui_thread_(content::BrowserThread::UI, &message_loop_), - profile_(new TestingProfile()), - dispatched_reports_count_(0), - expected_reports_(0) { - FeedbackUploaderFactory::GetInstance()->SetTestingFactory( - profile_.get(), &CreateFeedbackUploaderService); - - uploader_ = FeedbackUploaderFactory::GetForBrowserContext(profile_.get()); - uploader_->setup_for_test( - base::Bind(&FeedbackUploaderTest::MockDispatchReport, - base::Unretained(this)), - kRetryDelayForTest); - } - - virtual ~FeedbackUploaderTest() { - FeedbackUploaderFactory::GetInstance()->SetTestingFactory( - profile_.get(), NULL); - } - - void QueueReport(const std::string& data) { - uploader_->QueueReport(data); - } - - void ReportFailure(const std::string& data) { - uploader_->RetryReport(data); - } - - void MockDispatchReport(const std::string& report_data) { - if (ContainsKey(dispatched_reports_, report_data)) { - dispatched_reports_[report_data]++; - } else { - dispatched_reports_[report_data] = 1; - } - dispatched_reports_count_++; - - // Dispatch will always update the timer, whether successful or not, - // simulate the same behavior. - uploader_->UpdateUploadTimer(); - - if (ProcessingComplete()) { - if (run_loop_.get()) - run_loop_->Quit(); - } - } - - bool ProcessingComplete() { - return (dispatched_reports_count_ >= expected_reports_); - } - - void RunMessageLoop() { - if (ProcessingComplete()) - return; - run_loop_.reset(new base::RunLoop()); - run_loop_->Run(); - } - - base::MessageLoop message_loop_; - scoped_ptr<base::RunLoop> run_loop_; - content::TestBrowserThread ui_thread_; - scoped_ptr<TestingProfile> profile_; - - FeedbackUploader* uploader_; - - std::map<std::string, unsigned int> dispatched_reports_; - size_t dispatched_reports_count_; - size_t expected_reports_; -}; - -#if defined(OS_LINUX) || defined(OS_MACOSX) -#define MAYBE_QueueMultiple QueueMultiple -#else -// crbug.com/330547 -#define MAYBE_QueueMultiple DISABLED_QueueMultiple -#endif -TEST_F(FeedbackUploaderTest, MAYBE_QueueMultiple) { - dispatched_reports_.clear(); - QueueReport(kReportOne); - QueueReport(kReportTwo); - QueueReport(kReportThree); - QueueReport(kReportFour); - - EXPECT_EQ(dispatched_reports_.size(), 4u); - EXPECT_EQ(dispatched_reports_[kReportOne], 1u); - EXPECT_EQ(dispatched_reports_[kReportTwo], 1u); - EXPECT_EQ(dispatched_reports_[kReportThree], 1u); - EXPECT_EQ(dispatched_reports_[kReportFour], 1u); -} - -#if defined(OS_WIN) || defined(OS_ANDROID) -// crbug.com/330547 -#define MAYBE_QueueMultipleWithFailures DISABLED_QueueMultipleWithFailures -#else -#define MAYBE_QueueMultipleWithFailures QueueMultipleWithFailures -#endif -TEST_F(FeedbackUploaderTest, MAYBE_QueueMultipleWithFailures) { - dispatched_reports_.clear(); - - QueueReport(kReportOne); - QueueReport(kReportTwo); - QueueReport(kReportThree); - QueueReport(kReportFour); - - ReportFailure(kReportThree); - ReportFailure(kReportTwo); - QueueReport(kReportFive); - - expected_reports_ = 7; - RunMessageLoop(); - - EXPECT_EQ(dispatched_reports_.size(), 5u); - EXPECT_EQ(dispatched_reports_[kReportOne], 1u); - EXPECT_EQ(dispatched_reports_[kReportTwo], 2u); - EXPECT_EQ(dispatched_reports_[kReportThree], 2u); - EXPECT_EQ(dispatched_reports_[kReportFour], 1u); - EXPECT_EQ(dispatched_reports_[kReportFive], 1u); -} - -} // namespace feedback diff --git a/chrome/browser/feedback/feedback_util.cc b/chrome/browser/feedback/feedback_util.cc deleted file mode 100644 index 23e5406..0000000 --- a/chrome/browser/feedback/feedback_util.cc +++ /dev/null @@ -1,275 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/feedback/feedback_util.h" - -#include <sstream> -#include <string> -#include <vector> - -#include "base/bind.h" -#include "base/command_line.h" -#include "base/file_util.h" -#include "base/file_version_info.h" -#include "base/memory/singleton.h" -#include "base/message_loop/message_loop.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/stringprintf.h" -#include "base/strings/utf_string_conversions.h" -#include "base/win/windows_version.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h" -#include "chrome/browser/feedback/feedback_data.h" -#include "chrome/browser/feedback/feedback_uploader.h" -#include "chrome/browser/feedback/feedback_uploader_factory.h" -#include "chrome/browser/metrics/variations/variations_http_header_provider.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_manager.h" -#include "chrome/browser/safe_browsing/safe_browsing_util.h" -#include "chrome/browser/ui/browser_finder.h" -#include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "chrome/common/chrome_content_client.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/chrome_version_info.h" -#include "components/metrics/metrics_log_manager.h" -#include "content/public/browser/navigation_controller.h" -#include "content/public/browser/web_contents.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "grit/theme_resources.h" -#include "net/base/load_flags.h" -#include "net/http/http_request_headers.h" -#include "net/url_request/url_fetcher.h" -#include "net/url_request/url_fetcher_delegate.h" -#include "net/url_request/url_request_status.h" -#include "third_party/icu/source/common/unicode/locid.h" -#include "third_party/zlib/google/zip.h" -#include "ui/base/l10n/l10n_util.h" -#include "url/gurl.h" - -namespace { - -GURL GetTargetTabUrl(int session_id, int index) { - Browser* browser = chrome::FindBrowserWithID(session_id); - // Sanity checks. - if (!browser || index >= browser->tab_strip_model()->count()) - return GURL(); - - if (index >= 0) { - content::WebContents* target_tab = - browser->tab_strip_model()->GetWebContentsAt(index); - if (target_tab) - return target_tab->GetURL(); - } - - return GURL(); -} - -const char kPngMimeType[] = "image/png"; -const char kArbitraryMimeType[] = "application/octet-stream"; -const char kHistogramsAttachmentName[] = "histograms.zip"; -const char kLogsAttachmentName[] = "system_logs.zip"; - -#if defined(OS_CHROMEOS) -const int kChromeOSProductId = 208; -#else -const int kChromeBrowserProductId = 237; -#endif - -void AddFeedbackData(userfeedback::ExtensionSubmit* feedback_data, - const std::string& key, const std::string& value) { - // Don't bother with empty keys or values - if (key == "" || value == "") return; - // Create log_value object and add it to the web_data object - userfeedback::ProductSpecificData log_value; - log_value.set_key(key); - log_value.set_value(value); - userfeedback::WebData* web_data = feedback_data->mutable_web_data(); - *(web_data->add_product_specific_data()) = log_value; -} - -// Adds data as an attachment to feedback_data if the data is non-empty. -void AddAttachment(userfeedback::ExtensionSubmit* feedback_data, - const char* name, - std::string* data) { - if (data == NULL || data->empty()) - return; - - userfeedback::ProductSpecificBinaryData* attachment = - feedback_data->add_product_specific_binary_data(); - attachment->set_mime_type(kArbitraryMimeType); - attachment->set_name(name); - attachment->set_data(*data); -} - -} // namespace - -namespace chrome { - -const char kAppLauncherCategoryTag[] = "AppLauncher"; - -void ShowFeedbackPage(Browser* browser, - const std::string& description_template, - const std::string& category_tag) { - GURL page_url; - if (browser) { - page_url = GetTargetTabUrl(browser->session_id().id(), - browser->tab_strip_model()->active_index()); - } - - Profile* profile = NULL; - if (browser) { - profile = browser->profile(); - } else { - profile = ProfileManager::GetLastUsedProfileAllowedByPolicy(); - } - if (!profile) { - LOG(ERROR) << "Cannot invoke feedback: No profile found!"; - return; - } - - // We do not want to launch on an OTR profile. - profile = profile->GetOriginalProfile(); - DCHECK(profile); - - extensions::FeedbackPrivateAPI* api = - extensions::FeedbackPrivateAPI::GetFactoryInstance()->Get(profile); - - api->RequestFeedback(description_template, - category_tag, - page_url); -} - -} // namespace chrome - -namespace feedback_util { - -void SendReport(scoped_refptr<FeedbackData> data) { - if (!data.get()) { - LOG(ERROR) << "SendReport called with NULL data!"; - NOTREACHED(); - return; - } - - userfeedback::ExtensionSubmit feedback_data; - // Unused field, needs to be 0 though. - feedback_data.set_type_id(0); - - userfeedback::CommonData* common_data = feedback_data.mutable_common_data(); - // We're not using gaia ids, we're using the e-mail field instead. - common_data->set_gaia_id(0); - common_data->set_user_email(data->user_email()); - common_data->set_description(data->description()); - - std::string chrome_locale = g_browser_process->GetApplicationLocale(); - common_data->set_source_description_language(chrome_locale); - - userfeedback::WebData* web_data = feedback_data.mutable_web_data(); - web_data->set_url(data->page_url()); - web_data->mutable_navigator()->set_user_agent(GetUserAgent()); - - gfx::Rect screen_size; - if (data->sys_info()) { - for (FeedbackData::SystemLogsMap::const_iterator i = - data->sys_info()->begin(); i != data->sys_info()->end(); ++i) { - if (FeedbackData::BelowCompressionThreshold(i->second)) - AddFeedbackData(&feedback_data, i->first, i->second); - } - - AddAttachment(&feedback_data, kLogsAttachmentName, data->compressed_logs()); - } - - if (data->histograms()) { - AddAttachment(&feedback_data, - kHistogramsAttachmentName, - data->compressed_histograms()); - } - - if (!data->attached_filename().empty()) { - // We need to use the UTF8Unsafe methods here to accomodate Windows, which - // uses wide strings to store filepaths. - std::string name = base::FilePath::FromUTF8Unsafe( - data->attached_filename()).BaseName().AsUTF8Unsafe(); - AddAttachment(&feedback_data, name.c_str(), data->attached_filedata()); - } - - // NOTE: Screenshot needs to be processed after system info since we'll get - // the screenshot dimensions from system info. - if (data->image() && data->image()->size()) { - userfeedback::PostedScreenshot screenshot; - screenshot.set_mime_type(kPngMimeType); - - // Set that we 'have' dimensions of the screenshot. These dimensions are - // ignored by the server but are a 'required' field in the protobuf. - userfeedback::Dimensions dimensions; - dimensions.set_width(0.0); - dimensions.set_height(0.0); - - *(screenshot.mutable_dimensions()) = dimensions; - screenshot.set_binary_content(*data->image()); - - *(feedback_data.mutable_screenshot()) = screenshot; - } - - if (data->category_tag().size()) - feedback_data.set_bucket(data->category_tag()); - - // Set whether we're reporting from ChromeOS or Chrome on another platform. - userfeedback::ChromeData chrome_data; -#if defined(OS_CHROMEOS) - chrome_data.set_chrome_platform( - userfeedback::ChromeData_ChromePlatform_CHROME_OS); - userfeedback::ChromeOsData chrome_os_data; - chrome_os_data.set_category( - userfeedback::ChromeOsData_ChromeOsCategory_OTHER); - *(chrome_data.mutable_chrome_os_data()) = chrome_os_data; - feedback_data.set_product_id(kChromeOSProductId); -#else - chrome_data.set_chrome_platform( - userfeedback::ChromeData_ChromePlatform_CHROME_BROWSER); - userfeedback::ChromeBrowserData chrome_browser_data; - chrome_browser_data.set_category( - userfeedback::ChromeBrowserData_ChromeBrowserCategory_OTHER); - *(chrome_data.mutable_chrome_browser_data()) = chrome_browser_data; - feedback_data.set_product_id(kChromeBrowserProductId); -#endif - - *(feedback_data.mutable_chrome_data()) = chrome_data; - - // This pointer will eventually get deleted by the PostCleanup class, after - // we've either managed to successfully upload the report or died trying. - std::string post_body; - feedback_data.SerializeToString(&post_body); - - feedback::FeedbackUploader *uploader = - feedback::FeedbackUploaderFactory::GetForBrowserContext(data->profile()); - uploader->QueueReport(post_body); -} - -bool ZipString(const base::FilePath& filename, - const std::string& data, std::string* compressed_logs) { - base::FilePath temp_path; - base::FilePath zip_file; - - // Create a temporary directory, put the logs into a file in it. Create - // another temporary file to receive the zip file in. - if (!base::CreateNewTempDirectory(base::FilePath::StringType(), &temp_path)) - return false; - if (base::WriteFile(temp_path.Append(filename), data.c_str(), data.size()) == - -1) - return false; - - bool succeed = base::CreateTemporaryFile(&zip_file) && - zip::Zip(temp_path, zip_file, false) && - base::ReadFileToString(zip_file, compressed_logs); - - base::DeleteFile(temp_path, true); - base::DeleteFile(zip_file, false); - - return succeed; -} - -} // namespace feedback_util diff --git a/chrome/browser/feedback/feedback_util.h b/chrome/browser/feedback/feedback_util.h deleted file mode 100644 index 1fc9e64..0000000 --- a/chrome/browser/feedback/feedback_util.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_FEEDBACK_FEEDBACK_UTIL_H_ -#define CHROME_BROWSER_FEEDBACK_FEEDBACK_UTIL_H_ - -#include <string> - -#include "base/basictypes.h" -#include "base/files/file_path.h" -#include "base/memory/ref_counted.h" -#include "chrome/browser/feedback/proto/common.pb.h" -#include "chrome/browser/feedback/proto/dom.pb.h" -#include "chrome/browser/feedback/proto/extension.pb.h" -#include "chrome/browser/feedback/proto/math.pb.h" -#include "ui/gfx/rect.h" - -#if defined(OS_MACOSX) -#include "base/sys_info.h" -#elif defined(OS_WIN) -#include "base/win/windows_version.h" -#endif - -class FeedbackData; -class Profile; - -namespace content { -class WebContents; -} - -namespace chrome { -extern const char kAppLauncherCategoryTag[]; -} // namespace chrome - -namespace feedback_util { - - void SendReport(scoped_refptr<FeedbackData> data); - bool ZipString(const base::FilePath& filename, - const std::string& data, std::string* compressed_data); - -} // namespace feedback_util - -#endif // CHROME_BROWSER_FEEDBACK_FEEDBACK_UTIL_H_ diff --git a/chrome/browser/feedback/proto/annotations.proto b/chrome/browser/feedback/proto/annotations.proto deleted file mode 100644 index d14751a..0000000 --- a/chrome/browser/feedback/proto/annotations.proto +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Messages containing data about the annotations drawn on the screenshot of a -// web page. - -syntax = "proto2"; - -option optimize_for = LITE_RUNTIME; - -package userfeedback; - -import "math.proto"; -import "dom.proto"; - -// An annotation drawn by the user on the screenshot of a web page. -message Annotation { - // A rectangular area covered by this annotation on annotated image. - // The (0, 0) coordinate is placed in the top-left corner of the image. - // One unit corresponds to one pixel. - required Rectangle rectangle = 1; - - // A snippet of text displayed inside annotated portion of a web page. - optional string snippet = 2; - - // A path from root element of the document to the annotated element. - optional HtmlPath annotatedElementPath = 3; -}; diff --git a/chrome/browser/feedback/proto/chrome.proto b/chrome/browser/feedback/proto/chrome.proto deleted file mode 100644 index c721b06..0000000 --- a/chrome/browser/feedback/proto/chrome.proto +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -syntax = "proto2"; - -option optimize_for = LITE_RUNTIME; - -package userfeedback; - -// Chrome Browser and Chrome OS specific data. -message ChromeData { - // Encapsulates the priorities of Buganizer issues. - enum ChromePlatform { - CHROME_OS = 1; - CHROME_BROWSER = 2; - } - - // What platform has a report been sent from. - optional ChromePlatform chrome_platform = 1 [default = CHROME_OS]; - - optional ChromeOsData chrome_os_data = 2; - - optional ChromeBrowserData chrome_browser_data = 3; -} - -message ChromeOsData { - enum ChromeOsCategory { - CONNECTIVITY = 1; - SYNC = 2; - CRASH = 3; - PAGE_FORMATTING_OR_LAYOUT = 4; - EXTENSIONS_OR_APPS = 5; - STANDBY_OR_RESUME = 6; - PHISHING_PAGE = 7; - OTHER = 8; - AUTOFILL = 9; - } - - optional ChromeOsCategory category = 1 [default = OTHER]; -} - -message ChromeBrowserData{ - - enum ChromeBrowserCategory { - PAGE_FORMATTING_OR_LAYOUT = 1; - PAGES_NOT_LOADING = 2; - PLUGINS = 3; - TABS_OR_WINDOWS = 4; - SYNCED_PREFERENCES = 5; - CRASH = 6; - EXTENSIONS_OR_APPS = 7; - PHISHING_PAGE = 8; - OTHER = 9; - AUTOFILL = 10; - } - - optional ChromeBrowserCategory category = 1 [default = OTHER]; -} - diff --git a/chrome/browser/feedback/proto/common.proto b/chrome/browser/feedback/proto/common.proto deleted file mode 100644 index 5e028eb..0000000 --- a/chrome/browser/feedback/proto/common.proto +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Basic messages used by all systems (extension, feedbackserver, -// silver-bullet clustering, android etc). - -syntax = "proto2"; - -option optimize_for = LITE_RUNTIME; - -package userfeedback; - -// Data present in all kinds of feedbacks, regardless of source (Web, Android, -// other). -message CommonData { - optional fixed64 gaia_id = 1; - - // Description of the problem entered by user. - optional string description = 2; - optional string description_translated = 4; - optional string source_description_language = 5 [ default = "en" ]; - optional string ui_language = 6 [ default = "en_US" ]; - - optional string user_email = 3; - - // Unique identifier of feedback report. If set than only one report - // with the same identifier is stored in the system. - // If you are not sure how to use it leave it not set. - optional string unique_report_identifier = 7; -}; diff --git a/chrome/browser/feedback/proto/config.proto b/chrome/browser/feedback/proto/config.proto deleted file mode 100644 index f178912..0000000 --- a/chrome/browser/feedback/proto/config.proto +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Messages containing configuration of Feedback Service -// that control classification and processing of submitted feedbacks. - -syntax = "proto2"; - -option optimize_for = LITE_RUNTIME; - -package userfeedback; - -// Product for which feedback can be sent: GMail, Writely etc. -message Product { - required int32 id = 1; - - required string name = 2; - - repeated string owner = 3; -}; - -// Contains information needed to check whether particular -// feedback type applies to the page user is browsing and forward -// it's execution to a specific handler. It also carries information -// about the creator. -// TODO(morgwai): design new structure of Type with fields relevant -// for android, web, selenium grouped into submessages. -message FeedbackTypeData { - // index of feedback type as found in database - required int32 id = 1; - - // Specifies whether this feedback type is currently enabled and - // feedback of this type can be submitted. - required bool enabled = 2; - - // Problem name of this feedback type on Google Feedback pages. - required string problem_name = 3; - - // Name of the product to which this feedback type belongs. - optional string product_name = 4; - - // Tag 5 is used by some legacy data that is already in production db. - - // matcher to execute against page - required MatcherData matcher = 6; - - // Comma separated list of email addresses to which email notification - // is sent upon each new feedback of this type. - // No email is sent if this field is set to an empty string. - required string notification_email = 7; - - // Do not use tag 8, 9, 10. They were used by a legacy field. - - // Encapsulates different kind of feedback type. - enum Kind { - // Product feedback type. - PRODUCT = 1; - // Special feedback type (e.g. fixit). - SPECIAL = 2; - } - - // Kind of feedback type. - optional Kind kind = 11 [default=PRODUCT]; - - // Prefix to be added to summary of notification email sent for feedback of this - // type. - optional string summary_prefix = 12; - - // String template with which "Additional Info" field in extension - // should be initially filled. - optional string template = 13; - - // ID of the product this feedback type belongs to. - optional int32 product_id = 14; - - // Tag that is used for marking feedback types that require non-ordinary handling. - // E.g: This field is equal: - // "unclassified" for Unclassified feedback, - // "android" for android feedback - // "selenium" for selenium feedback - optional string tag = 15; - - // Problem description visible in feedback extension. - optional string problem_description = 16; - - // Visibilities of feedback type. - enum Visibility { - // feedback type visible in external extension only - EXTERNAL = 1; - // feedback type visible in internal extension only - INTERNAL = 2; - } - - // Specifies the visibility of this feedback type. - optional Visibility visibility = 17 [default=INTERNAL]; - - // tag 18 was used by removed field - - // Specifies Buganizer fields - // TODO(kaczmarek): enable once we migrated to new protos. - // optional BuganizerSettings buganizer_settings = 19; - - // Channel via which notification about feedback should be send - enum NotifyChannel { - // Send email notification. - EMAIL = 1; - // File a bug in buganizer. - BUGANIZER = 2; - // File a bug in issue tracker. - ISSUE_TRACKER = 3; - } - - // Specifies channel via which notification about feedback of this type should be sent. - optional NotifyChannel notify_channel = 20 [default=EMAIL]; - - // Granularity of notifications. - enum NotificationGranularity { - // Send notification per each feedback. - FEEDBACK = 1; - // Send notification per clustered group of similar feedbacks. - CLUSTER = 2; - } - - // Specifies granularity of notifications send for feedbacks of this type. - optional NotificationGranularity notification_granularity = 21 [default=FEEDBACK]; - - // Threshold for number of feedbacks in a cluster at which notification is sent. - optional int32 clustering_threshold = 22 [default=5]; -}; - -// Used to detect content relevant to particular type of feedback. -message MatcherData { - // XPATH expression to match against page. - required string content_matcher = 1; - - // Regexp matching page URL. - required string url_matcher = 2; - - // Approval by feedback admins - optional bool url_matcher_approved = 3 [default=true]; -}; diff --git a/chrome/browser/feedback/proto/dom.proto b/chrome/browser/feedback/proto/dom.proto deleted file mode 100644 index f5d1bc3..0000000 --- a/chrome/browser/feedback/proto/dom.proto +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Messages containing DOM data captured from the browser. -// It includes the structure of the HTML document and Navigator data. - -syntax = "proto2"; - -option optimize_for = LITE_RUNTIME; - -package userfeedback; - -// Data captured from HTMLDocument DOM object. -message HtmlDocument { - - // The value of document.URL property. - required string url = 1; - - // The value of document.title property. - optional string title = 2; - - // The value of document.documentElement property. - optional HtmlElement document_element = 3; -}; - -// Data captured from HTMLElement DOM object. -message HtmlElement { - - // The value of element.tagName property. - required string tag_name = 1; - - // The value of element.id property. - optional string id = 2; - - // The value of element.className property. - optional string class_name = 3; - - // A list of child elements. - repeated HtmlElement child_element = 4; - - // The value of frame.contentDocument property for FRAME and IFRAME elements. - optional HtmlDocument frame_content_document = 5; -}; - -// Data captured from DOM Navigator object. -message Navigator { - - // The value of 'navigator.appCodeName' property. - optional string app_code_name = 1; - - // The value of 'navigator.appName' property. - optional string app_name = 2; - - // The value of 'navigator.appVersion' property. - optional string app_version = 3; - - // The value of 'navigator.appMinorVersion' property. - optional string app_minor_version = 4; - - // The value of 'navigator.cookieEnabled' property. - optional bool cookie_enabled = 5; - - // The value of 'navigator.cpuClass' property. - optional string cpu_class = 6; - - // The value of 'navigator.onLine' property. - optional bool on_line = 7; - - // The value of 'navigator.platform' property. - optional string platform = 8; - - // The value of 'navigator.browserLanguage' property. - optional string browser_language = 9; - - // The value of 'navigator.systemLanguage' property. - optional string system_language = 10; - - // The value of 'navigator.userAgent' property. - optional string user_agent = 11; - - // The return value of 'navigator.javaEnabled()' method. - optional bool java_enabled = 12; - - // The return value of 'navigator.taintEnabled()' method. - optional bool taint_enabled = 13; - - // Plugin names specified by 'navigator.plugins' property. - repeated string plugin_name = 14; -}; - -// A path in the HTML document between two elements, which are in the -// ancestor-descendant relationship. -message HtmlPath { - - // Ordered list of zero-based indices. - // Empty path selects root element. - // Non-negative index N selects (N+1)-th child. - // Index -1 selects root element from frame content document. - repeated int32 index = 1; -}; diff --git a/chrome/browser/feedback/proto/extension.proto b/chrome/browser/feedback/proto/extension.proto deleted file mode 100644 index ff1fe48..0000000 --- a/chrome/browser/feedback/proto/extension.proto +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Messages sent from extension to feedback server as JSON. - -syntax = "proto2"; - -option optimize_for = LITE_RUNTIME; - -package userfeedback; - -import "common.proto"; -import "chrome.proto"; -import "dom.proto"; -import "math.proto"; -import "web.proto"; - -// Sent along with request for extension page when user attempts to open -// feedback tab. -message ExtensionPageRequestParams { - - required ExtensionDetails extension_details = 1; - - // Url of the page (without request params) that user wants to open - // feedback tool for. - required string url = 2; -}; - -message PostedScreenshot { - - required string mime_type = 1; - - required Dimensions dimensions = 2; - - optional string base64_content = 3; - - optional bytes binary_content = 4; -}; - -// Contains data about possible errors on the client side. -// Describes number of attempts to send feedback and possible error codes/ -// exceptions which occured. -message ExtensionErrors { - - required int32 number_of_attempts = 1; - - required string errors = 2; -}; - -// Sent when user hits final submit button. -message ExtensionSubmit { - - required CommonData common_data = 1; - - required WebData web_data = 2; - - required int32 type_id = 3; - - optional PostedScreenshot screenshot = 4; - - optional ChromeData chrome_data = 14; - - repeated ProductSpecificBinaryData product_specific_binary_data = 15; - - optional string category_tag = 16; - - optional int32 product_id = 17; - - optional string bucket = 18; -}; - -// A query for suggestions, sent when the user hits the preview button. -message SuggestQuery { - - required CommonData common_data = 1; - - required WebData web_data = 2; - - required int32 type_id = 3; - - optional HtmlDocument html_document_structure = 4; - - optional ChromeData chrome_data = 5; -}; diff --git a/chrome/browser/feedback/proto/math.proto b/chrome/browser/feedback/proto/math.proto deleted file mode 100644 index 6d8d5cb..0000000 --- a/chrome/browser/feedback/proto/math.proto +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Messages containing common math data structures. - -syntax = "proto2"; - -option optimize_for = LITE_RUNTIME; - -package userfeedback; - -// 2D Dimensions. -message Dimensions { - required float width = 1; - required float height = 2; -}; - -// Axis-aligned rectangle in 2D space. -message Rectangle { - required float left = 1; - required float top = 2; - required float width = 3; - required float height = 4; -}; diff --git a/chrome/browser/feedback/proto/web.proto b/chrome/browser/feedback/proto/web.proto deleted file mode 100644 index 024ef29..0000000 --- a/chrome/browser/feedback/proto/web.proto +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -syntax = "proto2"; - -package userfeedback; - -option optimize_for = LITE_RUNTIME; - -// Data present in Web related feedbacks - -import "annotations.proto"; -import "dom.proto"; -import "math.proto"; - -// Data present in feedbacks sent from web extension. -message WebData { - // Data captured from DOM Navigator object. - optional Navigator navigator = 1; - - // Details of the extension from which this data was sent. - optional ExtensionDetails extension_details = 2; - - // The URL of the document. - // Useful when user opts out from sending html structure. - optional string url = 3; - - // A list of annotations. - repeated Annotation annotation = 4; - - // The ID of the suggestion selected by the user. - // Possible values: - // - Not set if no suggestions were shown, either because the version of - // the client did not support suggestions, suggestions were disabled or - // no matching suggestions were found. - // - NONE_OF_THE_ABOVE if the user has chosen "None of the above". - // - Empty string if suggestions were shown but the user hasn't chosen - // any of them (and also she hasn't chosen "None of the above"). - // - Actual suggestion identifier as returned from the server. - optional string suggestion_id = 5; - - repeated ProductSpecificData product_specific_data = 6; - - // Name of the binary data stored. Replicated from - // ProductSpecificBinaryData.name which is stored as a separate - // column in Feedbacks3 megastore table. - repeated string product_specific_binary_data_name = 7; -}; - -message ExtensionDetails { - // Indicates browser and mpm release. - required string extension_version = 1; - - required string protocol_version = 2; -}; - -// Additional data sent by the internal version. -message InternalWebData { - // List of user names in google.com domain to which feedback should be sent - // directly apart from submitting it to server. - repeated string email_receiver = 1; - - // Subject of the problem entered by user. - optional string subject = 2; - - // If this flag is set then product support team should be notified - // immediately. - optional bool DEPRECATED_urgent = 3 [default = false]; -}; - -// Product specific data. Contains one key/value pair that is specific to the -// product for which feedback is submitted. -message ProductSpecificData { - required string key = 1; - optional string value = 2; -}; - -message ProductSpecificBinaryData { - required string name = 1; - - // mime_type of data - optional string mime_type = 2; - - // raw data - optional bytes data = 3; -}; diff --git a/chrome/browser/feedback/show_feedback_page.cc b/chrome/browser/feedback/show_feedback_page.cc new file mode 100644 index 0000000..828dee0 --- /dev/null +++ b/chrome/browser/feedback/show_feedback_page.cc @@ -0,0 +1,72 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <string> + +#include "chrome/browser/browser_process.h" +#include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/ui/browser_finder.h" +#include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "content/public/browser/web_contents.h" +#include "url/gurl.h" + +namespace { + +GURL GetTargetTabUrl(int session_id, int index) { + Browser* browser = chrome::FindBrowserWithID(session_id); + // Sanity checks. + if (!browser || index >= browser->tab_strip_model()->count()) + return GURL(); + + if (index >= 0) { + content::WebContents* target_tab = + browser->tab_strip_model()->GetWebContentsAt(index); + if (target_tab) + return target_tab->GetURL(); + } + + return GURL(); +} + +} // namespace + +namespace chrome { + +extern const char kAppLauncherCategoryTag[] = "AppLauncher"; + +void ShowFeedbackPage(Browser* browser, + const std::string& description_template, + const std::string& category_tag) { + GURL page_url; + if (browser) { + page_url = GetTargetTabUrl(browser->session_id().id(), + browser->tab_strip_model()->active_index()); + } + + Profile* profile = NULL; + if (browser) { + profile = browser->profile(); + } else { + profile = ProfileManager::GetLastUsedProfileAllowedByPolicy(); + } + if (!profile) { + LOG(ERROR) << "Cannot invoke feedback: No profile found!"; + return; + } + + // We do not want to launch on an OTR profile. + profile = profile->GetOriginalProfile(); + DCHECK(profile); + + extensions::FeedbackPrivateAPI* api = + extensions::FeedbackPrivateAPI::GetFactoryInstance()->Get(profile); + + api->RequestFeedback(description_template, + category_tag, + page_url); +} + +} // namespace chrome diff --git a/chrome/browser/feedback/tracing_manager.cc b/chrome/browser/feedback/tracing_manager.cc deleted file mode 100644 index 577a7c1..0000000 --- a/chrome/browser/feedback/tracing_manager.cc +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/feedback/tracing_manager.h" - -#include "base/bind.h" -#include "base/file_util.h" -#include "base/location.h" -#include "base/memory/ref_counted_memory.h" -#include "base/message_loop/message_loop_proxy.h" -#include "base/prefs/pref_service.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/feedback/feedback_util.h" -#include "chrome/common/pref_names.h" -#include "content/public/browser/tracing_controller.h" - -namespace { -// Only once trace manager can exist at a time. -TracingManager* g_tracing_manager = NULL; -// Trace IDs start at 1 and increase. -int g_next_trace_id = 1; -// Name of the file to store the tracing data as. -const base::FilePath::CharType kTracingFilename[] = - FILE_PATH_LITERAL("tracing.json"); -} - -TracingManager::TracingManager() - : current_trace_id_(0), - weak_ptr_factory_(this) { - DCHECK(!g_tracing_manager); - g_tracing_manager = this; - StartTracing(); -} - -TracingManager::~TracingManager() { - DCHECK(g_tracing_manager == this); - g_tracing_manager = NULL; -} - -int TracingManager::RequestTrace() { - // Return the current trace if one is being collected. - if (current_trace_id_) - return current_trace_id_; - - current_trace_id_ = g_next_trace_id; - ++g_next_trace_id; - content::TracingController::GetInstance()->DisableRecording( - base::FilePath(), - base::Bind(&TracingManager::OnTraceDataCollected, - weak_ptr_factory_.GetWeakPtr())); - return current_trace_id_; -} - -bool TracingManager::GetTraceData(int id, const TraceDataCallback& callback) { - // If a trace is being collected currently, send it via callback when - // complete. - if (current_trace_id_) { - // Only allow one trace data request at a time. - if (trace_callback_.is_null()) { - trace_callback_ = callback; - return true; - } else { - return false; - } - } else { - std::map<int, scoped_refptr<base::RefCountedString> >::iterator data = - trace_data_.find(id); - if (data == trace_data_.end()) - return false; - - // Always return the data asychronously, so the behavior is consistant. - base::MessageLoopProxy::current()->PostTask( - FROM_HERE, - base::Bind(callback, data->second)); - return true; - } -} - -void TracingManager::DiscardTraceData(int id) { - trace_data_.erase(id); - - // If the trace is discarded before it is complete, clean up the accumulators. - if (id == current_trace_id_) { - current_trace_id_ = 0; - - // If the trace has already been requested, provide an empty string. - if (!trace_callback_.is_null()) { - trace_callback_.Run(scoped_refptr<base::RefCountedString>()); - trace_callback_.Reset(); - } - } -} - -void TracingManager::StartTracing() { - content::TracingController::GetInstance()->EnableRecording( - "", content::TracingController::DEFAULT_OPTIONS, - content::TracingController::EnableRecordingDoneCallback()); -} - -void TracingManager::OnTraceDataCollected(const base::FilePath& path) { - if (!current_trace_id_) - return; - - std::string data; - if (!base::ReadFileToString(path, &data)) { - LOG(ERROR) << "Failed to read trace data from: " << path.value(); - return; - } - base::DeleteFile(path, false); - - std::string output_val; - feedback_util::ZipString( - base::FilePath(kTracingFilename), data, &output_val); - - scoped_refptr<base::RefCountedString> output( - base::RefCountedString::TakeString(&output_val)); - - trace_data_[current_trace_id_] = output; - - if (!trace_callback_.is_null()) { - trace_callback_.Run(output); - trace_callback_.Reset(); - } - - current_trace_id_ = 0; - - // Tracing has to be restarted asynchronous, so the TracingController can - // clean up. - base::MessageLoopProxy::current()->PostTask( - FROM_HERE, - base::Bind(&TracingManager::StartTracing, - weak_ptr_factory_.GetWeakPtr())); -} - -// static -scoped_ptr<TracingManager> TracingManager::Create() { - if (g_tracing_manager) - return scoped_ptr<TracingManager>(); - return scoped_ptr<TracingManager>(new TracingManager()); -} - -TracingManager* TracingManager::Get() { - return g_tracing_manager; -} diff --git a/chrome/browser/feedback/tracing_manager.h b/chrome/browser/feedback/tracing_manager.h deleted file mode 100644 index 5fd5588..0000000 --- a/chrome/browser/feedback/tracing_manager.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_FEEDBACK_TRACING_MANAGER_H_ -#define CHROME_BROWSER_FEEDBACK_TRACING_MANAGER_H_ - -#include <map> -#include <string> - -#include "base/basictypes.h" -#include "base/callback.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" - -namespace base { - -class RefCountedString; -class FilePath; - -} -// Callback used for getting the output of a trace. -typedef base::Callback<void(scoped_refptr<base::RefCountedString> trace_data)> - TraceDataCallback; - -// This class is used to manage performance metrics that can be attached to -// feedback reports. This class is a Singleton that is owned by the preference -// system. It should only be created when it is enabled, and should only be -// accessed elsewhere via Get(). -// -// When a performance trace is desired, TracingManager::Get()->RequestTrace() -// should be invoked. The TracingManager will then start preparing a zipped -// version of the performance data. That data can then be requested via -// GetTraceData(). When the data is no longer needed, it should be discarded -// via DiscardTraceData(). -class TracingManager { - public: - virtual ~TracingManager(); - - // Create a TracingManager. Can only be called when none exists. - static scoped_ptr<TracingManager> Create(); - - // Get the current TracingManager. Returns NULL if one doesn't exist. - static TracingManager* Get(); - - // Request a trace ending at the current time. If a trace is already being - // collected, the id for that trace is returned. - int RequestTrace(); - - // Get the trace data for |id|. On success, true is returned, and the data is - // returned via |callback|. Returns false on failure. - bool GetTraceData(int id, const TraceDataCallback& callback); - - // Discard the data for trace |id|. - void DiscardTraceData(int id); - - private: - TracingManager(); - - void StartTracing(); - void OnTraceDataCollected(const base::FilePath& path); - - // ID of the trace that is being collected. - int current_trace_id_; - - // Mapping of trace ID to trace data. - std::map<int, scoped_refptr<base::RefCountedString> > trace_data_; - - // Callback for the current trace request. - TraceDataCallback trace_callback_; - - base::WeakPtrFactory<TracingManager> weak_ptr_factory_; - - DISALLOW_COPY_AND_ASSIGN(TracingManager); -}; - -#endif // CHROME_BROWSER_FEEDBACK_TRACING_MANAGER_H_ - |