| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "chrome/browser/ui/webui/crashes_ui.h" | 5 #include "chrome/browser/ui/webui/crashes_ui.h" | 
| 6 | 6 | 
| 7 #include <vector> | 7 #include <vector> | 
| 8 | 8 | 
| 9 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 82 | 82 | 
| 83  private: | 83  private: | 
| 84   // Asynchronously fetches the list of crashes. Called from JS. | 84   // Asynchronously fetches the list of crashes. Called from JS. | 
| 85   void HandleRequestCrashes(const ListValue* args); | 85   void HandleRequestCrashes(const ListValue* args); | 
| 86 | 86 | 
| 87   // Sends the recent crashes list JS. | 87   // Sends the recent crashes list JS. | 
| 88   void UpdateUI(); | 88   void UpdateUI(); | 
| 89 | 89 | 
| 90   scoped_refptr<CrashUploadList> upload_list_; | 90   scoped_refptr<CrashUploadList> upload_list_; | 
| 91   bool list_available_; | 91   bool list_available_; | 
| 92   bool js_request_pending_; | 92   bool first_load_; | 
| 93 | 93 | 
| 94   DISALLOW_COPY_AND_ASSIGN(CrashesDOMHandler); | 94   DISALLOW_COPY_AND_ASSIGN(CrashesDOMHandler); | 
| 95 }; | 95 }; | 
| 96 | 96 | 
| 97 CrashesDOMHandler::CrashesDOMHandler() | 97 CrashesDOMHandler::CrashesDOMHandler() | 
| 98     : list_available_(false), js_request_pending_(false) { | 98     : list_available_(false), first_load_(true) { | 
| 99   upload_list_ = CrashUploadList::Create(this); | 99   upload_list_ = CrashUploadList::Create(this); | 
| 100 } | 100 } | 
| 101 | 101 | 
| 102 CrashesDOMHandler::~CrashesDOMHandler() { | 102 CrashesDOMHandler::~CrashesDOMHandler() { | 
| 103   upload_list_->ClearDelegate(); | 103   upload_list_->ClearDelegate(); | 
| 104 } | 104 } | 
| 105 | 105 | 
| 106 void CrashesDOMHandler::RegisterMessages() { | 106 void CrashesDOMHandler::RegisterMessages() { | 
| 107   upload_list_->LoadUploadListAsynchronously(); | 107   upload_list_->LoadUploadListAsynchronously(); | 
| 108 |  | 
| 109   web_ui()->RegisterMessageCallback("requestCrashList", | 108   web_ui()->RegisterMessageCallback("requestCrashList", | 
| 110       base::Bind(&CrashesDOMHandler::HandleRequestCrashes, | 109       base::Bind(&CrashesDOMHandler::HandleRequestCrashes, | 
| 111                  base::Unretained(this))); | 110                  base::Unretained(this))); | 
| 112 } | 111 } | 
| 113 | 112 | 
| 114 void CrashesDOMHandler::HandleRequestCrashes(const ListValue* args) { | 113 void CrashesDOMHandler::HandleRequestCrashes(const ListValue* args) { | 
| 115   if (!CrashesUI::CrashReportingUIEnabled() || list_available_) | 114   if (first_load_) { | 
| 116     UpdateUI(); | 115     first_load_ = false; | 
| 117   else | 116     if (list_available_) | 
| 118     js_request_pending_ = true; | 117       UpdateUI(); | 
|  | 118   } else { | 
|  | 119     list_available_ = false; | 
|  | 120     upload_list_->LoadUploadListAsynchronously(); | 
|  | 121   } | 
| 119 } | 122 } | 
| 120 | 123 | 
| 121 void CrashesDOMHandler::OnUploadListAvailable() { | 124 void CrashesDOMHandler::OnUploadListAvailable() { | 
| 122   list_available_ = true; | 125   list_available_ = true; | 
| 123   if (js_request_pending_) | 126   if (!first_load_) | 
| 124     UpdateUI(); | 127     UpdateUI(); | 
| 125 } | 128 } | 
| 126 | 129 | 
| 127 void CrashesDOMHandler::UpdateUI() { | 130 void CrashesDOMHandler::UpdateUI() { | 
| 128   bool crash_reporting_enabled = CrashesUI::CrashReportingUIEnabled(); | 131   bool crash_reporting_enabled = CrashesUI::CrashReportingUIEnabled(); | 
| 129   ListValue crash_list; | 132   ListValue crash_list; | 
| 130 | 133 | 
| 131   if (crash_reporting_enabled) { | 134   if (crash_reporting_enabled) { | 
| 132     std::vector<CrashUploadList::UploadInfo> crashes; | 135     std::vector<CrashUploadList::UploadInfo> crashes; | 
| 133     upload_list_->GetUploads(50, &crashes); | 136     upload_list_->GetUploads(50, &crashes); | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 186   PrefService* prefs = g_browser_process->local_state(); | 189   PrefService* prefs = g_browser_process->local_state(); | 
| 187   return prefs->GetBoolean(prefs::kCrashReportingEnabled); | 190   return prefs->GetBoolean(prefs::kCrashReportingEnabled); | 
| 188 #else | 191 #else | 
| 189   PrefService* prefs = g_browser_process->local_state(); | 192   PrefService* prefs = g_browser_process->local_state(); | 
| 190   return prefs->GetBoolean(prefs::kMetricsReportingEnabled); | 193   return prefs->GetBoolean(prefs::kMetricsReportingEnabled); | 
| 191 #endif | 194 #endif | 
| 192 #else | 195 #else | 
| 193   return false; | 196   return false; | 
| 194 #endif | 197 #endif | 
| 195 } | 198 } | 
| OLD | NEW | 
|---|