[Password Manager] Export error message is localised

We want to show a basic error message to the user, if exporting the
passwords to the filesystem fails.

Bug: 789561
Change-Id: Ieff5a590dd882374494c3d23c2aef0ff89734545
Reviewed-on: https://chromium-review.googlesource.com/803484
Commit-Queue: Christos Froussios <cfroussios@chromium.org>
Reviewed-by: Vaclav Brozek <vabr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520999}
diff --git a/chrome/browser/ui/passwords/destination_file_system.cc b/chrome/browser/ui/passwords/destination_file_system.cc
index 0a14712..730d01f 100644
--- a/chrome/browser/ui/passwords/destination_file_system.cc
+++ b/chrome/browser/ui/passwords/destination_file_system.cc
@@ -7,12 +7,27 @@
 #include <utility>
 
 #include "base/files/file_util.h"
+#include "base/strings/utf_string_conversions.h"
+#include "build/build_config.h"
+#include "components/strings/grit/components_strings.h"
+#include "ui/base/l10n/l10n_util.h"
 
 DestinationFileSystem::DestinationFileSystem(base::FilePath destination_path)
     : destination_path_(std::move(destination_path)) {}
 
-bool DestinationFileSystem::Write(const std::string& data) {
-  return base::WriteFile(destination_path_, data.c_str(), data.size());
+base::string16 DestinationFileSystem::Write(const std::string& data) {
+  if (base::WriteFile(destination_path_, data.c_str(), data.size())) {
+    return base::string16();
+  } else {
+#if defined(OS_WIN)
+    base::string16 folder_name(destination_path_.DirName().BaseName().value());
+#else
+    base::string16 folder_name(
+        base::UTF8ToUTF16(destination_path_.DirName().BaseName().value()));
+#endif
+    return l10n_util::GetStringFUTF16(
+        IDS_PASSWORD_MANAGER_EXPORT_TO_FILE_FAILED, std::move(folder_name));
+  }
 }
 
 const base::FilePath& DestinationFileSystem::GetDestinationPathForTesting() {
diff --git a/chrome/browser/ui/passwords/destination_file_system.h b/chrome/browser/ui/passwords/destination_file_system.h
index a6ea278..8ae9167 100644
--- a/chrome/browser/ui/passwords/destination_file_system.h
+++ b/chrome/browser/ui/passwords/destination_file_system.h
@@ -17,7 +17,7 @@
   ~DestinationFileSystem() override = default;
 
   // password_manager::Destination
-  bool Write(const std::string& data) override;
+  base::string16 Write(const std::string& data) override;
 
   // Get this instance's target.
   const base::FilePath& GetDestinationPathForTesting();
diff --git a/components/password_manager/core/browser/export/destination.h b/components/password_manager/core/browser/export/destination.h
index 342601e..a0987a1 100644
--- a/components/password_manager/core/browser/export/destination.h
+++ b/components/password_manager/core/browser/export/destination.h
@@ -16,8 +16,9 @@
   Destination() = default;
   virtual ~Destination() = default;
 
-  // Send the data to the destination, synchronously.
-  virtual bool Write(const std::string& data) = 0;
+  // Send the data to the destination, synchronously. On failure, a
+  // human-readable error message will be returned.
+  virtual base::string16 Write(const std::string& data) = 0;
 };
 
 }  // namespace password_manager
diff --git a/components/password_manager/core/browser/export/password_manager_exporter_unittest.cc b/components/password_manager/core/browser/export/password_manager_exporter_unittest.cc
index 48dec4b..2ab2407 100644
--- a/components/password_manager/core/browser/export/password_manager_exporter_unittest.cc
+++ b/components/password_manager/core/browser/export/password_manager_exporter_unittest.cc
@@ -59,7 +59,7 @@
   MockDestination() = default;
   ~MockDestination() override = default;
 
-  MOCK_METHOD1(Write, bool(const std::string& data));
+  MOCK_METHOD1(Write, base::string16(const std::string& data));
 
  private:
   DISALLOW_COPY_AND_ASSIGN(MockDestination);
diff --git a/components/password_manager_strings.grdp b/components/password_manager_strings.grdp
index cfc7a00..d0647b2 100644
--- a/components/password_manager_strings.grdp
+++ b/components/password_manager_strings.grdp
@@ -19,5 +19,8 @@
   <message name="IDS_PASSWORD_MANAGER_DEFAULT_EXPORT_FILENAME" desc="Chrome suggests this file name when user chooses to export their passwords saved with Chrome.">
     Chrome Passwords
   </message>
+  <message name="IDS_PASSWORD_MANAGER_EXPORT_TO_FILE_FAILED" desc="Chrome tried to export the passwords to a file and failed. This message will be the title of the error message that will be shown to the user.">
+    Can't export passwords to "<ph name="folder">$1<ex>Desktop</ex></ph>"
+  </message>
 
 </grit-part>