Closed Bug 1288320 Opened 8 years ago Closed 8 years ago

Define each keysystem string as specific identifier instead of placing "some.keysystem" everywhere.

Categories

(Core :: Audio/Video: Playback, defect, P3)

defect

Tracking

()

RESOLVED FIXED
mozilla50
Tracking Status
firefox50 --- fixed

People

(Reporter: kikuo, Assigned: JamesCheng)

References

Details

Attachments

(1 file)

Per Bug 1136707 Comment 10, the code would be clearer and easier to remember.
e.g.
#define EME_KEYSYSTEM_WIDEVINE    "com.widevine.alpha"
#define EME_KEYSYSTEM_PLAYREADY   "com.microsoft.playready"
#define EME_KEYSYSTEM_CLEARKEY    "org.w3.clearkey"
#define EME_KEYSYSTEM_PRIMETIME   "com.adobe.primetime"
Is gecko programmer encouraged to use const instead of macro?

such as static const char* const EME_KEYSYSTEM_PLAYREADY = "com.microsoft.playready";
Assignee: nobody → jacheng
Hi Chris,

I just tried to unified the literal string into const string. 

I searched from DXR and cannot find the united naming rule for |static const string|.

So I used prefix 'k', camel case and put then in EMEUtils.h.

Please address me of the naming and if there is a more appropriate header to declare the string.

Thank you very much.
Why not using macros as suggested by comment 0?
Intuitively, I think macro is not a good coding style and refer to "Item 2 : Prefer consts, enums, and inlines to #defines" from Scott Meyers". 

So I just ask comment1 that is there any policy or guideline to determine we should use macro or not.
I can't think of a way to define literal strings without macro.
Since we're quoting Meyers:

http://flylib.com/books/en/2.887.1.13/1/

<quote>
Because constant definitions are typically put in header files (where many different source files will include them), it's important that the pointer be declared const, usually in addition to what the pointer points to. To define a constant char*-based string in a header file, for example, you have to write const twice:

 const char * const authorName = "Scott Meyers";

</quote>

You could probably instead also define the string as "extern" in the header, and define it in a .cpp file somewhere. I'd rather just have the "const char* const" literal in the header I think.

And our coding style guide says constant literals start with a 'k' prefix, though its not consistent and some use all caps.
https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Coding_Style#Literals

So please use the pattern:

  const char * const kName = "literal";
Comment on attachment 8775066 [details]
Bug 1288320 - Define each keysystem string as specific identifier instead of placing some.keysystem everywhere.

https://reviewboard.mozilla.org/r/67392/#review64616
Attachment #8775066 - Flags: review?(cpearce) → review+
Thanks for the reviewing!
Keywords: checkin-needed
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/5f98e30cc66e
Define each keysystem string as specific identifier instead of placing some.keysystem everywhere. r=cpearce
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/5f98e30cc66e
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla50
Depends on: 1293194
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: