OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/translate/translate_tab_helper.h" | 5 #include "chrome/browser/translate/translate_tab_helper.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 #if defined(CLD2_DYNAMIC_MODE) | 36 #if defined(CLD2_DYNAMIC_MODE) |
37 #include "base/files/file.h" | 37 #include "base/files/file.h" |
38 #include "base/path_service.h" | 38 #include "base/path_service.h" |
39 #include "chrome/common/chrome_constants.h" | 39 #include "chrome/common/chrome_constants.h" |
40 #include "chrome/common/chrome_paths.h" | 40 #include "chrome/common/chrome_paths.h" |
41 #include "content/public/browser/browser_thread.h" | 41 #include "content/public/browser/browser_thread.h" |
42 #include "content/public/browser/render_process_host.h" | 42 #include "content/public/browser/render_process_host.h" |
43 #include "content/public/browser/render_view_host.h" | 43 #include "content/public/browser/render_view_host.h" |
44 #endif | 44 #endif |
45 | 45 |
| 46 #if defined(CLD2_IS_COMPONENT) |
| 47 #include "chrome/browser/component_updater/cld_component_installer.h" |
| 48 #endif |
| 49 |
46 namespace { | 50 namespace { |
47 | 51 |
48 // The maximum number of attempts we'll do to see if the page has finshed | 52 // The maximum number of attempts we'll do to see if the page has finshed |
49 // loading before giving up the translation | 53 // loading before giving up the translation |
50 const int kMaxTranslateLoadCheckAttempts = 20; | 54 const int kMaxTranslateLoadCheckAttempts = 20; |
51 | 55 |
52 } // namespace | 56 } // namespace |
53 | 57 |
54 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TranslateTabHelper); | 58 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TranslateTabHelper); |
55 | 59 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 384 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
381 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 385 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
382 | 386 |
383 { | 387 { |
384 base::AutoLock lock(s_file_lock_.Get()); | 388 base::AutoLock lock(s_file_lock_.Get()); |
385 if (s_cached_file_) | 389 if (s_cached_file_) |
386 return; // Already done, duplicate request | 390 return; // Already done, duplicate request |
387 } | 391 } |
388 | 392 |
389 base::FilePath path; | 393 base::FilePath path; |
| 394 #if defined(CLD2_IS_COMPONENT) |
| 395 if (!component_updater::GetLatestCldDataFile(&path)) |
| 396 return; |
| 397 #else |
390 if (!PathService::Get(chrome::DIR_USER_DATA, &path)) { | 398 if (!PathService::Get(chrome::DIR_USER_DATA, &path)) { |
391 LOG(WARNING) << "Unable to locate user data directory"; | 399 LOG(WARNING) << "Unable to locate user data directory"; |
392 return; // Chrome isn't properly installed. | 400 return; // Chrome isn't properly installed. |
393 } | 401 } |
394 | |
395 // If the file exists, we can send an IPC-safe construct back to the | 402 // If the file exists, we can send an IPC-safe construct back to the |
396 // renderer process immediately. | 403 // renderer process immediately. |
397 path = path.Append(chrome::kCLDDataFilename); | 404 path = path.Append(chrome::kCLDDataFilename); |
398 if (!base::PathExists(path)) | 405 if (!base::PathExists(path)) |
399 return; | 406 return; |
| 407 #endif |
400 | 408 |
401 // Attempt to open the file for reading. | 409 // Attempt to open the file for reading. |
402 scoped_ptr<base::File> file( | 410 scoped_ptr<base::File> file( |
403 new base::File(path, base::File::FLAG_OPEN | base::File::FLAG_READ)); | 411 new base::File(path, base::File::FLAG_OPEN | base::File::FLAG_READ)); |
404 if (!file->IsValid()) { | 412 if (!file->IsValid()) { |
405 LOG(WARNING) << "CLD data file exists but cannot be opened"; | 413 LOG(WARNING) << "CLD data file exists but cannot be opened"; |
406 return; | 414 return; |
407 } | 415 } |
408 | 416 |
409 base::File::Info file_info; | 417 base::File::Info file_info; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 if (GetLanguageState().InTranslateNavigation()) | 530 if (GetLanguageState().InTranslateNavigation()) |
523 return; | 531 return; |
524 } | 532 } |
525 | 533 |
526 TranslateBubbleFactory::Show( | 534 TranslateBubbleFactory::Show( |
527 browser->window(), web_contents(), step, error_type); | 535 browser->window(), web_contents(), step, error_type); |
528 #else | 536 #else |
529 NOTREACHED(); | 537 NOTREACHED(); |
530 #endif | 538 #endif |
531 } | 539 } |
OLD | NEW |