OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/common/extensions/extension_file_util.h" | 5 #include "chrome/common/extensions/extension_file_util.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/histogram.h" | |
14 #include "base/path_service.h" | |
13 #include "base/scoped_temp_dir.h" | 15 #include "base/scoped_temp_dir.h" |
16 #include "base/threading/thread_restrictions.h" | |
14 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "chrome/common/chrome_paths.h" | |
15 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
16 #include "chrome/common/extensions/extension_action.h" | 20 #include "chrome/common/extensions/extension_action.h" |
17 #include "chrome/common/extensions/extension_l10n_util.h" | 21 #include "chrome/common/extensions/extension_l10n_util.h" |
18 #include "chrome/common/extensions/extension_constants.h" | 22 #include "chrome/common/extensions/extension_constants.h" |
19 #include "chrome/common/extensions/extension_resource.h" | 23 #include "chrome/common/extensions/extension_resource.h" |
20 #include "chrome/common/json_value_serializer.h" | 24 #include "chrome/common/json_value_serializer.h" |
21 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
22 #include "net/base/escape.h" | 26 #include "net/base/escape.h" |
23 #include "net/base/file_stream.h" | 27 #include "net/base/file_stream.h" |
24 | 28 |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 | 514 |
511 // It's still possible for someone to construct an annoying URL whose path | 515 // It's still possible for someone to construct an annoying URL whose path |
512 // would still wind up not being considered relative at this point. | 516 // would still wind up not being considered relative at this point. |
513 // For example: chrome-extension://id/c:////foo.html | 517 // For example: chrome-extension://id/c:////foo.html |
514 if (path.IsAbsolute()) | 518 if (path.IsAbsolute()) |
515 return FilePath(); | 519 return FilePath(); |
516 | 520 |
517 return path; | 521 return path; |
518 } | 522 } |
519 | 523 |
524 FilePath GetUserDataTempDir() { | |
525 // We do file IO in this function, but only when the current profile | |
526 // has never had an extension installed, or in a rare error. Developers | |
Erik does not do reviews
2011/01/18 21:36:34
"has never used the profile temp dir before" (I be
Sam Kerner (Chrome)
2011/01/19 05:01:24
Done.
| |
527 // are not likely to run into these cases often, so do an explicit thread | |
528 // check. | |
529 base::ThreadRestrictions::AssertIOAllowed(); | |
530 | |
531 // crbug.com/67627: Getting chrome::DIR_USER_DATA_TEMP is failing. | |
532 // Use histogram to see why. | |
Erik does not do reviews
2011/01/18 21:36:34
add TODO remove this code when fixed
Sam Kerner (Chrome)
2011/01/19 05:01:24
Done.
| |
533 enum DirectoryCreationResult { | |
534 SUCCESS = 0, | |
535 | |
536 CANT_GET_PARENT_PATH, | |
537 CANT_GET_UDT_PATH, | |
538 NOT_A_DIRECTORY, | |
539 CANT_CREATE_DIR, | |
540 CANT_WRITE_TO_PATH, | |
541 | |
542 UNSET, | |
543 NUM_DIRECTORY_CREATION_RESULTS | |
544 }; | |
545 | |
546 // All paths should set |result|. | |
547 DirectoryCreationResult result = UNSET; | |
548 | |
549 FilePath temp_path; | |
550 if (!PathService::Get(chrome::DIR_USER_DATA_TEMP, &temp_path)) { | |
551 FilePath parent_path; | |
552 if (!PathService::Get(chrome::DIR_USER_DATA, &parent_path)) | |
553 result = CANT_GET_PARENT_PATH; | |
554 else | |
555 result = CANT_GET_UDT_PATH; | |
556 | |
557 } else if (file_util::PathExists(temp_path)) { | |
558 | |
559 // Path exists. Check that it is a directory we can write to. | |
560 if (!file_util::DirectoryExists(temp_path)) { | |
561 result = NOT_A_DIRECTORY; | |
562 | |
563 } else if (!file_util::PathIsWritable(temp_path)) { | |
564 result = CANT_WRITE_TO_PATH; | |
565 | |
566 } else { | |
567 // Temp is a writable directory. | |
568 result = SUCCESS; | |
569 } | |
570 | |
571 } else if (!file_util::CreateDirectory(temp_path)) { | |
572 // Path doesn't exist, and we failed to create it. | |
573 result = CANT_CREATE_DIR; | |
574 | |
575 } else { | |
576 // Successfully created the Temp directory. | |
577 result = SUCCESS; | |
578 } | |
579 | |
580 UMA_HISTOGRAM_ENUMERATION("Extensions.GetUserDataTempDir", | |
581 result, | |
582 NUM_DIRECTORY_CREATION_RESULTS); | |
583 | |
584 if (result == SUCCESS) | |
585 return temp_path; | |
586 | |
587 return FilePath(); | |
588 } | |
589 | |
520 } // namespace extension_file_util | 590 } // namespace extension_file_util |
OLD | NEW |